public async Task <JsonResult> SaveDay(List <UserDayDish> daydishes) { //await _email.SendEmailAsync("*****@*****.**", "catering", "new order"); DateTime daydate = DateTime.Now; if (daydishes.Count > 0) { daydate = daydishes.First().Date; } else { return(await Task.FromResult(Json(new { res = "FAIL", reason = "Empty" }))); } if (!_userdaydishesrepo.IsAllowDayEdit(daydate, User.GetCompanyID())) { return(await Task.FromResult(Json(new { res = "FAIL", reason = "OutDate" }))); } await _email.SendInvoice(User.GetUserId(), daydate, User.GetCompanyID()); if (_userdaydishesrepo.SaveDay(daydishes, this.HttpContext)) { return(await Task.FromResult(Json(new { res = "OK" }))); } else { return(await Task.FromResult(Json(new { res = "FAIL", reason = "Error" }))); } /* * try * { * daydishes.ForEach(d => * { * //await saveday(d); * this.AssignUserAttr(d); * var userDayDish = _context.UserDayDish.Find(d.UserId, d.Date, d.DishId,d.CompanyId ); * if (userDayDish != null) * { * userDayDish.Quantity = d.Quantity; * userDayDish.Price = d.Price; * _context.Update(userDayDish); * } * else if(d.Quantity>0) * { * //d.UserId = this.User.GetUserId(); * * _context.Add(d); * } * * }); * await _context.SaveChangesAsync(); * } * catch(Exception ex) * { * _logger.LogError(ex, "Update user day dish"); * return await Task.FromResult(Json(new { res = "FAIL" })); * } * return await Task.FromResult(Json(new { res = "OK" })); */ }
public async Task <JsonResult> SaveDay(List <UserDayDish> daydishes) { //await _email.SendEmailAsync("*****@*****.**", "catering", "new order"); DateTime daydate = DateTime.Now; if (daydishes.Count > 0) { daydate = daydishes.First().Date; } else { return(await Task.FromResult(Json(new { res = "FAIL", reason = "Empty" }))); } if (!_userdaydishesrepo.IsAllowDayEdit(daydate, User.GetHotelID())) { return(await Task.FromResult(Json(new { res = "FAIL", reason = "OutDate" }))); } // await _email.SendInvoice(User.GetUserId(), daydate, User.GetHotelID()); if (_userdaydishesrepo.SaveDay(daydishes, this.HttpContext)) { return(await Task.FromResult(Json(new { res = "OK" }))); } else { return(await Task.FromResult(Json(new { res = "FAIL", reason = "Error" }))); } }