public ActionResult AddSupplier(RequestWareSupplierRequest[] requests) { //var requestWare = _da.GetRequestWareById(request.RequestWareId); //if (requestWare == null) //{ // return Json(new JsonMessage() { Erros = true, Message = "Request not exits" }, JsonRequestBehavior.AllowGet); //} //var requestWareSupplier = _da.GetRequestWareBySupplier(request.RequestWareId, request.SupplierId); //if (requestWareSupplier != null) //{ // return Json(new JsonMessage() { Erros = true, Message = "Nhà cung cấp đã được chọn" }, JsonRequestBehavior.AllowGet); //} ////kiem tra so luong //var all = _da.GetAllRequestWareByRequestWareId(request.RequestWareId); //if (all.Sum(m => m.Quantity) + request.Quantity > requestWare.Quantity) //{ // return Json(new JsonMessage() { Erros = true, Message = "Tổng số lượng lớn hơn thực duyệt" }, JsonRequestBehavior.AllowGet); //} foreach (var request in requests) { var requestWare = _da.GetRequestWareById(request.RequestWareId); if (requestWare == null) { return(Json(new JsonMessage() { Erros = true, Message = "Request not exits" }, JsonRequestBehavior.AllowGet)); } var requestWareSupplier = _da.GetRequestWareBySupplier(request.RequestWareId, request.SupplierId); if (requestWareSupplier != null) { return(Json(new JsonMessage() { Erros = true, Message = requestWareSupplier.DN_Supplier.Name + " đã được chọn" }, JsonRequestBehavior.AllowGet)); } var item = new DN_RequestWareSupplier() { RequestWareId = request.RequestWareId, SupplierId = request.SupplierId, Quantity = request.Quantity, IsDelete = false }; _da.AddRequestWareSupplier(item); } _da.Save(); return(Json(new JsonMessage() { Erros = false }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> AddSupplier(RequestWareSupplierRequest request) { var requestWare = _da.GetRequestWareById(request.RequestWareId); if (requestWare == null) { return(Json(new JsonMessage() { Erros = true, Message = "Request not exits" }, JsonRequestBehavior.AllowGet)); } //remove nha cung cap if (request.SupplierId == 0) { var requestSuppliers = _da.GetAllRequestWareByRequestWareId(requestWare.GID); foreach (var dnRequestWareSupplier in requestSuppliers) { dnRequestWareSupplier.IsDelete = true; } _da.Save(); return(Json(new JsonMessage(false, "Đã bỏ chọn NCC"))); } var requestWareSupplier = _da.GetRequestWareBySupplier(request.RequestWareId, request.SupplierId); if (requestWareSupplier != null) { return(Json(new JsonMessage() { Erros = true, Message = requestWareSupplier.DN_Supplier.Name + " đã được chọn" }, JsonRequestBehavior.AllowGet)); } var item = new DN_RequestWareSupplier() { RequestWareId = request.RequestWareId, SupplierId = request.SupplierId, Quantity = requestWare.Quantity ?? 0, IsDelete = false }; _da.AddRequestWareSupplier(item); _da.Save(); return(Json(new JsonMessage(false, "Đã thêm NCC"), JsonRequestBehavior.AllowGet)); }