1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BLL.Dto.RecipeDto;
- using DAL.Services;
- using Helper;
- using HZY.Framework.DependencyInjection;
- using Mapster;
- using Model;
- namespace BLL.Manager
- {
- internal class RecipeManager:IScopedSelfDependency
- {
- private readonly RecipeService _recipeService;
- public RecipeManager(RecipeService recipeService)
- {
- _recipeService = recipeService;
- }
- public async Task<BaseResult> AddRecipeAsync(AddRecipeDto request)
- {
- var isExist = await _recipeService.ExistAsync(e => e.产品类型 == request.产品类型);
- if (isExist)
- {
- return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "产品类型已存在" };
- }
- var entity = request.Adapt<RecipeEntity>();
- var res = await _recipeService.InsertAsync(entity);
- if (res > 0)
- {
- return new BaseResult() { Result = SystemEnums.Result.Success };
- }
- return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "添加失败" };
- }
- public async Task<BaseResult> UpdateRecipeAsync(UpdateRecipeDto request)
- {
- var isExsit = await _recipeService.ExistAsync(c => c.产品类型 == request.产品类型 && c.Id != request.Id);
- if (isExsit)
- {
- return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "修改的产品类型已存在" };
- }
- var entity = request.Adapt<RecipeEntity>();
- var res = await _recipeService.UpdateAsync(entity);
- if (res)
- {
- return new BaseResult() { Result = SystemEnums.Result.Success };
- }
- return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "更新失败" };
- }
- public async Task<BaseResult> DeleteRecipeAsync(DelRecipeDto request)
- {
- var entity = request.Adapt<RecipeEntity>();
- var res = await _recipeService.DeleteAsync(entity);
- if (res)
- {
- return new BaseResult() { Result = SystemEnums.Result.Success };
- }
- return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "删除失败" };
- }
- public async Task<BaseResult<QueryRecipeResultDto>> GetRecipeListAsync()
- {
- var res = await _recipeService.GetListAsync(c => true);
- var dtos = res.Adapt<List<QueryRecipeResultDto>>();
- return new BaseResult<QueryRecipeResultDto>() { Result = SystemEnums.Result.Success, Data = dtos };
- }
- public async Task<BaseResult<QueryRecipeResultDto>> GetRecipeAsyncById(GetRecipeByIdDto request)
- {
- var res = await _recipeService.GetByOneAsync(c => c.Id == request.Id);
- var dtos = res.Adapt<QueryRecipeResultDto>();
- return new BaseResult<QueryRecipeResultDto>() { Result = SystemEnums.Result.Success, Data = new List<QueryRecipeResultDto>() { dtos } };
- }
- }
- }
|