Пример #1
0
        public static List <MSouvenirVM> SearchData(MSouvenirVM model)
        {
            var data = new List <MSouvenirVM>();

            using (AppEntity db = new AppEntity())
            {
                data = db.m_souvenir.Select(x => new MSouvenirVM()
                {
                    id           = x.id,
                    code         = x.code,
                    name         = x.name,
                    description  = x.description,
                    m_unit_id    = x.m_unit_id,
                    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,
                    str_unit     = x.m_unit.name
                })
                       .Where(x => x.is_active == true && (x.code.Contains(model.code) || x.name.Contains(model.name) || x.m_unit_id == model.m_unit_id) || (x.created_date.Day == model.created_date.Day && x.created_date.Month == model.created_date.Month && x.created_date.Year == model.created_date.Year))
                       .ToList();
            }
            return(data);
        }
Пример #2
0
 public ActionResult Insert(MSouvenirVM model)
 {
     if (ModelState.IsValid)
     {
         if (MSouvenirRepo.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
         {
             MSouvenirRepo.Insert(model);
             var result = new
             {
                 success      = true,
                 alertType    = "info",
                 alertMessage = "Saved !",
                 alertStrong  = "Your Data With Code <strong>(" + model.code + ")</strong> is Saved"
             };
             return(Json(result, JsonRequestBehavior.AllowGet));
         }
     }
     return(PartialView("_Insert"));
 }
Пример #3
0
        public static MSouvenirVM GetId(int id)
        {
            var data = new MSouvenirVM();

            using (AppEntity db = new AppEntity())
            {
                data = db.m_souvenir.Select(x => new MSouvenirVM()
                {
                    id           = x.id,
                    code         = x.code,
                    name         = x.name,
                    description  = x.description,
                    m_unit_id    = x.m_unit_id,
                    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,
                    str_unit     = x.m_unit.name
                })
                       .Where(x => x.id == id)
                       .FirstOrDefault();
            }
            return(data);
        }
Пример #4
0
        public ActionResult SearchData(MSouvenirVM model)
        {
            var data = MSouvenirRepo.SearchData(model);

            if (data.Count == 0 && model.code == null && model.name == null && model.m_unit_id == 0 && model.created_date == DateTime.MinValue && model.created_by == 0)
            {
                data = MSouvenirRepo.GetAllData();
            }

            return(PartialView("_List", data));
        }
Пример #5
0
        public static bool CheckIfExists(MSouvenirVM model)
        {
            bool res = false;

            using (AppEntity db = new AppEntity())
            {
                var data = db.m_souvenir.Where(x => x.name == model.name && x.id != model.id).ToList();
                if (data.Count > 0)
                {
                    res = true;
                }
            }
            return(res);
        }
Пример #6
0
        public static bool Update(MSouvenirVM model)
        {
            bool res = false;

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

                try { db.SaveChanges(); res = true; } catch (Exception) { throw; }
            }
            return(res);
        }
Пример #7
0
        public static bool Insert(MSouvenirVM model)
        {
            bool res = false;

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

                db.m_souvenir.Add(data);
                try { db.SaveChanges(); res = true; } catch (Exception) { throw; }
            }
            return(res);
        }