public async Task <OperationResult> SaveAsync(SeleTransactionDto model, Guid userId) { var result = new OperationResult(); var report = await reportRepository.All().FirstOrDefaultAsync(x => x.Id == model.Id); //если добавятся другие рецепты , то у SeleTransaction добавиться новое поле var recipe = await recipeRepository.All().FirstOrDefaultAsync(); var currentAccount = await accountRepository.All().OrderByDescending(x => x.CreatedOn).FirstOrDefaultAsync(); try { if (report == null) { var newReport = mapper.Map <SeleTransaction>(model); currentAccount.TotalCash += model.TotalProfit; currentAccount.Kefir -= model.TotalKg * recipe.Kefir; currentAccount.Oil -= model.TotalKg * recipe.Oil; currentAccount.Salt -= model.TotalKg * recipe.Salt; currentAccount.Eggs -= model.TotalKg * recipe.Eggs; currentAccount.Vanila -= model.TotalKg * recipe.Vanila; currentAccount.Sugar -= model.TotalKg * recipe.Sugar; currentAccount.Soda -= model.TotalKg * recipe.Soda; reportRepository.Add(newReport); } else { //za4em dobavlyat ewe i braki oni ved ne vliyayut na kassy currentAccount.TotalCash += (model.TotalProfit - report.TotalProfit); currentAccount.Kefir -= (model.TotalKg - (report.CountOfKg + report.DefectiveKg)) * recipe.Kefir; //литр currentAccount.Oil -= (model.TotalKg - (report.CountOfKg + report.DefectiveKg)) * recipe.Oil; // литр currentAccount.Salt -= (model.TotalKg - (report.CountOfKg + report.DefectiveKg)) * recipe.Salt; // кг currentAccount.Eggs -= (model.TotalKg - (report.CountOfKg + report.DefectiveKg)) * recipe.Eggs; // штук currentAccount.Vanila -= (model.TotalKg - (report.CountOfKg + report.DefectiveKg)) * recipe.Vanila; // грамм currentAccount.Sugar -= (model.TotalKg - (report.CountOfKg + report.DefectiveKg)) * recipe.Sugar; // кг currentAccount.Soda -= (model.TotalKg - (report.CountOfKg + report.DefectiveKg)) * recipe.Soda; //грамм report.Date = model.Date; report.CountOfKg = model.CountOfKg; report.DefectiveKg = model.DefectiveKg; report.TotalProfit = model.TotalProfit; } await reportRepository.SaveChangesAsync(userId); } catch (Exception ex) { logger.LogError($"Exception: {ex.GetType()}; Сообщение об ошибке: {ex.Message}; StackTrace: {ex.StackTrace}"); } return(result); }
public async Task <IActionResult> CreateNewReportAsync(SeleTransactionDto model) { await selesReportService.SaveAsync(model, this.User.GetUserId()); return(RedirectToAction("Index", "SelesReport")); }