Esempio n. 1
0
 public ActionResult Update(MProductVM model)
 {
     if (ModelState.IsValid)
     {
         if (MProductRepo.CheckIfExists(model) == true)
         {
             var notif = new
             {
                 success      = false,
                 alertType    = "error",
                 alertMessage = "ERROR !",
                 alertStrong  = "Your Data With Name (" + model.name + ") is Already Exists"
             };
             return(Json(notif, JsonRequestBehavior.AllowGet));
         }
         else
         {
             MProductRepo.Update(model);
             var result = new
             {
                 success      = true,
                 alertType    = "info",
                 alertMessage = "Updated !",
                 alertStrong  = "Your Data With Code <strong>(" + model.code + ")</strong> is Updated"
             };
             return(Json(result, JsonRequestBehavior.AllowGet));
         }
     }
     return(PartialView("_Update"));
 }
Esempio n. 2
0
        public static bool CheckIfExists(MProductVM model)
        {
            bool res = false;

            using (AppEntity db = new AppEntity())
            {
                var data = db.m_product.Where(x => x.name == model.name && x.id != model.id).ToList();
                if (data.Count > 0)
                {
                    res = true;
                }
            }
            return(res);
        }
Esempio n. 3
0
        public static bool Update(MProductVM model)
        {
            bool res = false;

            using (AppEntity db = new AppEntity())
            {
                m_product data = db.m_product.Find(model.id);
                data.code         = model.code;
                data.name         = model.name;
                data.description  = model.description;
                data.updated_by   = 1;
                data.updated_date = DateTime.Now;

                try { db.SaveChanges(); res = true; } catch (Exception) { throw; }
            }
            return(res);
        }
Esempio n. 4
0
        public static bool Insert(MProductVM model, string userID)
        {
            bool res = false;

            using (AppEntity db = new AppEntity())
            {
                m_product data = new m_product()
                {
                    code         = model.code,
                    name         = model.name,
                    description  = model.description,
                    created_by   = 1,
                    created_date = DateTime.Now,
                    is_active    = true
                };

                db.m_product.Add(data);
                try { db.SaveChanges(); res = true; } catch (Exception) { throw; }
            }
            return(res);
        }
Esempio n. 5
0
        public static MProductVM GetId(int id)
        {
            var data = new MProductVM();

            using (AppEntity db = new AppEntity())
            {
                data = db.m_product.Select(x => new MProductVM()
                {
                    id           = x.id,
                    code         = x.code,
                    name         = x.name,
                    description  = x.description,
                    is_active    = x.is_active,
                    created_by   = x.created_by,
                    created_date = x.created_date,
                    updated_by   = x.updated_by,
                    updated_date = x.updated_date
                })
                       .Where(x => x.id == id)
                       .FirstOrDefault();
            }
            return(data);
        }