57 lines
2.4 KiB
C#
57 lines
2.4 KiB
C#
using AutoMapper;
|
|
using SessionCompanion.Database.Repositories.Base;
|
|
using SessionCompanion.Database.Tables;
|
|
using SessionCompanion.Services.Base;
|
|
using SessionCompanion.Services.Interfaces;
|
|
using SessionCompanion.ViewModels.CharacterViewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Linq;
|
|
using Microsoft.EntityFrameworkCore.Internal;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using AutoMapper.QueryableExtensions;
|
|
using System.IO;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace SessionCompanion.Services.Services
|
|
{
|
|
public class CharacterService : ServiceBase<CharacterViewModel, Character>, ICharacterService
|
|
{
|
|
public CharacterService(IMapper mapper, IRepository<Character> repository) : base(mapper, repository)
|
|
{ }
|
|
|
|
/// <summary>
|
|
/// Funkcja zwraca listę postaci przypisanych do podanego użytkownika
|
|
/// </summary>
|
|
/// <param name="userId">identyfikator użytkownika</param>
|
|
/// <returns>Lista postaci dosępnych dla podanego użytkownika</returns>
|
|
public async Task<IEnumerable<CharacterForLoginViewModel>> GetUserLoginCharacters(int userId)
|
|
{
|
|
var characters = await Repository.Get(c => c.UserId.Equals(userId))
|
|
.Include(x => x.Biography)
|
|
.Include(x => x.Statistics)
|
|
.Include(x => x.Biography).ThenInclude(b => b.Class).ToListAsync();
|
|
var result = Mapper.Map<IEnumerable<CharacterForLoginViewModel>>(characters);
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Funkcja zwraca podstawowy widok postaci na podstawie ich id
|
|
/// </summary>
|
|
/// <param name="charactersId">Lista identyfikatorów postaci</param>
|
|
/// <returns>Podstawowy widok podanych postaci</returns>
|
|
public async Task<IEnumerable<CharacterBasicStatsViewModel>> GetBasicCharactersData(List<int> charactersId)
|
|
{
|
|
var characters = await Repository.Get(c => charactersId.Contains(c.Id))
|
|
.Include(x => x.Biography)
|
|
.ThenInclude(x => x.Class)
|
|
.Include(x => x.Statistics).ToListAsync();
|
|
var result = Mapper.Map<IEnumerable<CharacterBasicStatsViewModel>>(characters);
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|