RecipeManager.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BLL.Dto.RecipeDto;
  7. using DAL.Services;
  8. using Helper;
  9. using HZY.Framework.DependencyInjection;
  10. using Mapster;
  11. using Model;
  12. namespace BLL.Manager
  13. {
  14. public class RecipeManager:IScopedSelfDependency
  15. {
  16. private readonly RecipeService _recipeService;
  17. public RecipeManager(RecipeService recipeService)
  18. {
  19. _recipeService = recipeService;
  20. }
  21. public async Task<BaseResult> AddRecipeAsync(AddRecipeDto request)
  22. {
  23. var isExist = await _recipeService.ExistAsync(e => e.产品类型 == request.产品类型);
  24. if (isExist)
  25. {
  26. return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "产品类型已存在" };
  27. }
  28. var entity = request.Adapt<RecipeEntity>();
  29. var res = await _recipeService.InsertAsync(entity);
  30. if (res > 0)
  31. {
  32. return new BaseResult() { Result = SystemEnums.Result.Success };
  33. }
  34. return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "添加失败" };
  35. }
  36. public async Task<BaseResult> UpdateRecipeAsync(UpdateRecipeDto request)
  37. {
  38. var isExsit = await _recipeService.ExistAsync(c => c.产品类型 == request.产品类型 && c.Id != request.Id);
  39. if (isExsit)
  40. {
  41. return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "修改的产品类型已存在" };
  42. }
  43. var entity = request.Adapt<RecipeEntity>();
  44. var res = await _recipeService.UpdateAsync(entity);
  45. if (res)
  46. {
  47. return new BaseResult() { Result = SystemEnums.Result.Success };
  48. }
  49. return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "更新失败" };
  50. }
  51. public async Task<BaseResult> DeleteRecipeAsync(DelRecipeDto request)
  52. {
  53. var entity = request.Adapt<RecipeEntity>();
  54. var res = await _recipeService.DeleteAsync(entity);
  55. if (res)
  56. {
  57. return new BaseResult() { Result = SystemEnums.Result.Success };
  58. }
  59. return new BaseResult() { Result = SystemEnums.Result.Fail, Msg = "删除失败" };
  60. }
  61. public async Task<BaseResult<QueryRecipeResultDto>> GetRecipeListAsync()
  62. {
  63. var res = await _recipeService.GetListAsync(c => true);
  64. var dtos = res.Adapt<List<QueryRecipeResultDto>>();
  65. return new BaseResult<QueryRecipeResultDto>() { Result = SystemEnums.Result.Success, Data = dtos };
  66. }
  67. public async Task<BaseResult<QueryRecipeResultDto>> GetRecipeAsyncById(GetRecipeByIdDto request)
  68. {
  69. var res = await _recipeService.GetByOneAsync(c => c.Id == request.Id);
  70. var dtos = res.Adapt<QueryRecipeResultDto>();
  71. return new BaseResult<QueryRecipeResultDto>() { Result = SystemEnums.Result.Success, Data = new List<QueryRecipeResultDto>() { dtos } };
  72. }
  73. }
  74. }