public static ReturnResult Save(ReturnOrderHeaderViewModel models) { ReturnResult result = new ReturnResult(); try { using (var db = new BuahSayurContext()) { string newRef = GetNewReference(); result.Reference = newRef; ReturnOrder returnOrder = new ReturnOrder { Id = 1, DeliveryOrder_Id = models.DeliveryOrder_Id, Reference = newRef, ReturnDate = models.ReturnDate, }; db.ReturnOrders.Add(returnOrder); foreach (var item in models.ReturnOrderDetails) { ReturnOrderDetail returnOrderDetail = new ReturnOrderDetail { Return_Id = returnOrder.Id, Item_Code = item.Item_Code, ReturnAmount = item.ReturnAmount, Replacement = item.Replacement, Shortage = item.Shortage, Status = item.Status }; db.ReturnOrderDetails.Add(returnOrderDetail); } // set IsReturned to true DeliveryOrder deliveryOrder = db.DeliveryOrders.Where(x => x.Id == models.DeliveryOrder_Id).FirstOrDefault(); deliveryOrder.IsReturned = true; db.SaveChanges(); } } catch (Exception ex) { result.Success = false; Message = ex.Message; } return(result); }
public ActionResult SaveRequestReturn(ReturnOrderHeaderViewModel models) { if (ModelState.IsValid) { ReturnResult result = ReturnDataAccess.Save(models); if (result.Success) { return(Json(new { success = true, message = "Success", data = result }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = ReturnDataAccess.Message }, JsonRequestBehavior.AllowGet)); } } return(Json(new { success = false, message = "Invalid Model State!" }, JsonRequestBehavior.AllowGet)); }