public async Task <IActionResult> CreateMealDishes([FromBody] AddMealDishesRequestDto request) { var verifyResult = VerifyDishes(request); if (verifyResult.Code != ErrorCode.Success) { return(verifyResult); } ; var dishesBiz = new MealDishesBiz(); var model = request.ToModel <MealDishesModel>(); model.DishesOnsale = 1; model.DishesGuid = Guid.NewGuid().ToString("N"); model.CreatedBy = UserID; model.LastUpdatedBy = UserID; model.OrgGuid = ""; var exsitName = await dishesBiz.ExistDishesName(request.HospitalGuid, request.DishesName.Trim()); if (exsitName) { return(Failed(ErrorCode.Empty, $"菜品“{request.DishesName}”已存在")); } var result = await dishesBiz.CreateDish(model); return(!string.IsNullOrEmpty(result) ? Success() : Failed(ErrorCode.DataBaseError, "菜品创建失败!")); }
public async Task <IActionResult> UpdateMealDishes([FromBody] AddMealDishesRequestDto request) { if (string.IsNullOrEmpty(request.DishesGuid)) { return(Failed(ErrorCode.Empty, "参数不正确")); } var verifyResult = VerifyDishes(request); if (verifyResult.Code != ErrorCode.Success) { return(verifyResult); } ; var dishesBiz = new MealDishesBiz(); var model = await dishesBiz.GetMealDishesModelById(request.HospitalGuid, request.DishesGuid); if (model is null) { return(Failed(ErrorCode.Empty, "菜品不存在")); } var existDishes = await dishesBiz.ExistDishesName(request.HospitalGuid, request.DishesName.Trim(), request.DishesGuid); if (existDishes) { return(Failed(ErrorCode.Empty, $"菜品“{request.DishesName}已存在”")); } model.DishesImg = request.DishesImg; model.DishesDescription = request.DishesDescription; model.DishesExternalPrice = request.DishesExternalPrice; model.DishesInternalPrice = request.DishesInternalPrice; model.DishesName = request.DishesName; model.LastUpdatedBy = UserID; model.LastUpdatedDate = DateTime.Now; var result = await dishesBiz.UpdateDish(model); return(result > 0 ? Success() : Failed(ErrorCode.DataBaseError, "菜品更新失败!")); }