using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Aurora.Core.Domain.Entities; using Aurora.Core.EntityFramework; using Aurora.Core.IService; using Aurora.Core.IService.Dto; using Aurora.Infrastructure.Response; using AutoMapper; using Microsoft.EntityFrameworkCore; namespace Aurora.Core.Service { public class RocketService : IRocketService { private readonly ApplicationDbContext _dbContext; private readonly ApplicationReadonlyDbContext _readonlyDbContext; private readonly IMapper _mapper; public RocketService(ApplicationDbContext dbContext, ApplicationReadonlyDbContext readonlyDbContext, IMapper mapper) { _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _dbContext = dbContext; _readonlyDbContext = readonlyDbContext; } public async Task>> GetList() { var list = await _readonlyDbContext.Categories.ToListAsync(); var dtoList = _mapper.Map>(list); var res = new ResponseModel>(dtoList); return res; } public async Task> GetById(int id) { var entity = await _readonlyDbContext.Categories.FirstOrDefaultAsync(m => m.ID == id); var dto = _mapper.Map(entity); var res = new ResponseModel(dto); return res; } public async Task> Rocket(RocketDto model) { #region 保存到数据库 var entity = _mapper.Map(model); _dbContext.RocketWords.Add(entity); var num = await _dbContext.SaveChangesAsync(); #endregion #region 发送到移动端 // 按照用户发送 // 广播发送 #endregion var dto = _mapper.Map(entity); var res = new ResponseModel(dto); return res; } } }