Example #1
0
        public IActionResult Create(web_db._Weighing.TblProduct model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.txt = "ثبت انجام نشد - فیلد ها را درست پر کنید";
                return(View(model));
            }
            try
            {
                var x = db.TblProducts.Find(model.Id);
                if (x == null)
                {
                    x = new web_db._Weighing.TblProduct {
                        Id = model.Id
                    };

                    db.TblProducts.Add(x);
                }
                x.Code     = model.Code;
                x.IsActive = model.IsActive;
                x.Title    = model.Title;


                x.OtcodeKala           = model.OtcodeKala;
                x.OtcodeKalaAcc        = model.OtcodeKalaAcc;
                x.OtcodeVahedShomaresh = model.OtcodeVahedShomaresh;
                x.IsNotAc    = model.IsNotAc;
                x.WightScale = model.WightScale;
                x.WightScale = x.WightScale == 0 ? null : x.WightScale;

                db.SaveChanges();
                ViewBag.txt            = "ثبت انجام شد";
                Models.cl._ListProduct = db.TblProducts.OrderBy(a => a.Code).ToList();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                ViewBag.error = "ثبت انجام نشد";
            }
            return(View(model));
        }
Example #2
0
        public IActionResult Create(Guid id)
        {
            var sal   = User._getuserSalMaliDef();
            var model = new web_db._Weighing.TblProduct()
            {
                Id = Guid.NewGuid(), IsActive = true
            };
            var x = db.TblProducts.Find(id);

            if (x == null)
            {
                model.Code = (db.TblProducts.Max(a => (int?)a.Code) ?? 0) + 1;
            }
            else
            {
                model = x;
            }

            return(View(model));
        }