示例#1
0
        public ActionResult Edit(PurchaseOrderModels model)
        {
            try
            {
                if (!model.StoreIntegrate)
                {
                    if (model.TaxType == (int)Commons.ETax.AddOn)
                    {
                        if (model.TaxValue < 0 || model.TaxValue > 100)
                        {
                            ModelState.AddModelError("TaxValue", CurrentUser.GetLanguageTextFromKey("Please enter a value greater than or equal to 0 and maximun 100%"));
                        }
                    }
                }
                if (model.DeliveryDate.Date < model.PODate.Date)
                {
                    ModelState.AddModelError("DeliveryDate", CurrentUser.GetLanguageTextFromKey("Delivery date cannot be sooner than PO date"));
                }
                model.ModifierBy   = CurrentUser.Email;
                model.ModifierDate = DateTime.Now;
                if (!ModelState.IsValid)
                {
                    //model = GetDetail(model.Id);
                    var ListSupplierInfo = GetListSuppliers(model.StoreID);
                    var ListSupplier     = new SelectList(ListSupplierInfo, "Id", "Name");
                    model.ListSupplier  = ListSupplier.ToList();
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
                //====================
                model.ListItem = model.ListItem.Where(x => x.Delete != (int)Commons.EStatus.Deleted).ToList();
                List <string> listItemOnData = _factory.listItemOnData(model.Id);
                var           listIdDelete   = listItemOnData.Where(a => !(model.ListItem.Select(x => x.Id).ToList()).Any(a1 => a1 == a)).ToList();

                string msg    = "";
                var    result = _factory.Update(model, listIdDelete, ref msg);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //model = GetDetail(model.Id);
                    var ListSupplierInfo = GetListSuppliers(model.StoreID);
                    var ListSupplier     = new SelectList(ListSupplierInfo, "Id", "Name");
                    model.ListSupplier = ListSupplier.ToList();
                    ModelState.AddModelError("StoreID", msg);
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("PurchaseOrderEdit: " + ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }