Beispiel #1
0
        public ActionResult AddOrEditConsumable(ConsumableMaterialModel model)
        {
            try
            {
                if (Int32.Parse(model.materialNumberRecipient) > Int32.Parse(model.materialQuantity))
                {
                    return(Json(new { success = false, message = "Value of 領用數量 cannot be greqter than 請購數量" }, JsonRequestBehavior.AllowGet));
                }

                if (Int32.Parse(model.materialGoodNumberReturn) > Int32.Parse(model.materialNumberRecipient))
                {
                    return(Json(new { success = false, message = "Value of 退庫良品數量 cannot be greqter than 領用數量" }, JsonRequestBehavior.AllowGet));
                }
                if (Int32.Parse(model.materialBadNumberReturn) > Int32.Parse(model.materialNumberRecipient))
                {
                    return(Json(new { success = false, message = "Value of 退庫不良數量 cannot be greqter than 領用數量" }, JsonRequestBehavior.AllowGet));
                }

                if (model.ImageUpload != null && model.materialImagePath != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName);
                    string extension = Path.GetExtension(model.ImageUpload.FileName);
                    fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    model.materialImagePath = "~/AppFiles/Images/" + fileName;
                    model.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName));
                }
                JSONReadWrite ex = new JSONReadWrite();
                if (!ex.checkCodeExistOrNot(model.materialCode))
                {
                    var result = ex.addNewConsumable(model);
                    if (result)
                    {
                        return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAlll", GetAllConsumableMaterial()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Add new Fail" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    var result = ex.editConsumable(model);
                    if (result)
                    {
                        return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAlll", GetAllConsumableMaterial()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Edit Fail" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }