83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using _0_Framework.InfraStructure;
|
|
using AccountManagement.Application.Contracts.Media;
|
|
using AccountManagement.Domain.AdminResponseMediaAgg;
|
|
using AccountManagement.Domain.ClientResponseMediaAgg;
|
|
using AccountManagement.Domain.MediaAgg;
|
|
using AccountManagement.Domain.TaskMediaAgg;
|
|
using AccountManagement.Domain.TicketMediasAgg;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace AccountMangement.Infrastructure.EFCore.Repository;
|
|
|
|
public class MediaRepository:RepositoryBase<long,Media>,IMediaRepository
|
|
{
|
|
private readonly AccountContext _accountContext;
|
|
public MediaRepository( AccountContext taskManagerContext) : base(taskManagerContext)
|
|
{
|
|
_accountContext = taskManagerContext;
|
|
}
|
|
//ساخت جدول واسط بین مدیا و نسک
|
|
//نکته: این متد ذخیره انجام نمیدهد
|
|
public void CreateMediaWithTaskMedia(long taskId, long mediaId)
|
|
{
|
|
var Taskmedias = new TaskMedia(taskId,mediaId);
|
|
_accountContext.Add(Taskmedias);
|
|
}
|
|
public void Remove(long id)
|
|
{
|
|
var media = Get(id);
|
|
Remove(media);
|
|
}
|
|
|
|
public void CreateTicketMedia(long ticketId, long mediaId)
|
|
{
|
|
var ticketMedias = new TicketMedia(ticketId, mediaId);
|
|
_accountContext.Add(ticketMedias);
|
|
}
|
|
|
|
public void CreateAdminResponseMedia(long adminResponseId, long mediaId)
|
|
{
|
|
var adminResMedia = new AdminResponseMedia(adminResponseId, mediaId);
|
|
_accountContext.Add(adminResMedia);
|
|
}
|
|
|
|
public void CreateClientResponseMedia(long clientResponseId, long mediaId)
|
|
{
|
|
var clientResMedia = new ClientResponseMedia(clientResponseId, mediaId);
|
|
_accountContext.Add(clientResMedia);
|
|
}
|
|
|
|
public List<MediaViewModel> GetMediaByTaskId(long taskId)
|
|
{
|
|
return _accountContext.TaskMedias.Include(x => x.Media).Where(x => x.TaskId == taskId).Select(x =>
|
|
new MediaViewModel()
|
|
{
|
|
Id = x.Media.id,
|
|
Path = x.Media.Path,
|
|
Type = x.Media.Type,
|
|
}).ToList();
|
|
}
|
|
|
|
#region Pooya
|
|
|
|
public List<MediaViewModel> GetMedias(List<long> ids)
|
|
{
|
|
return _accountContext.Medias.Where(x => ids.Contains(x.id)).Select(x => new MediaViewModel()
|
|
{
|
|
Id = x.id,
|
|
Path = x.Path,
|
|
Category = x.Category,
|
|
Type = x.Type
|
|
}).ToList();
|
|
}
|
|
|
|
public List<Media> GetRange(IEnumerable<long> mediaIds)
|
|
{
|
|
return _accountContext.Medias.Where(x => mediaIds.Contains(x.id)).ToList();
|
|
}
|
|
}
|
|
|
|
#endregion
|