Exemplo n.º 1
0
        public static bool Insert(VMMenu paramModel)
        {
            bool result = true;

            try
            {
                using (var db = new Markom_IDLEEntities())
                {
                    m_menu a = new m_menu();
                    a.code         = paramModel.code;
                    a.name         = paramModel.name;
                    a.controller   = paramModel.controller;
                    a.parent_id    = paramModel.parent_id;
                    a.is_delete    = paramModel.is_delete;
                    a.created_by   = paramModel.created_by;
                    a.created_date = paramModel.created_date;

                    db.m_menu.Add(a);
                    db.SaveChanges();
                }
            }
            catch (Exception hasError)
            {
                result = false;
                if (hasError.Message.ToLower().Contains("inner exception"))
                {
                    Message = hasError.InnerException.InnerException.Message;
                }
                else
                {
                    Message = hasError.Message;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public static bool Delete(VMMenu paramModel)
        {
            bool result = true;

            try
            {
                using (var db = new Markom_IDLEEntities())
                {
                    m_menu a = db.m_menu.Where(o => o.id == paramModel.id).FirstOrDefault();
                    if (a != null)
                    {
                        a.is_delete = true;

                        db.SaveChanges();
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception hasError)
            {
                result = false;
                if (hasError.Message.ToLower().Contains("inner exception"))
                {
                    Message = hasError.InnerException.InnerException.Message;
                }
                else
                {
                    Message = hasError.Message;
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        //insert
        //menerima view model dari view
        public static bool insert(MMenuVM model)
        {
            bool result = false;

            //simpan datanya ke model
            using (AppEntity db = new AppEntity())
            {
                m_menu item = new m_menu()
                {
                    id           = model.id,
                    code         = model.code,
                    name         = model.name,
                    controller   = model.controller,
                    parent_id    = model.parent_id,
                    is_active    = true,
                    created_by   = 1,
                    created_date = DateTime.Now,
                    updated_by   = 1,
                    updated_date = DateTime.Now,
                };
                db.m_menu.Add(item);

                try
                {
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        // delete
        // update
        public static bool hiddenMenu(int id)
        {
            var result = false;

            MMenuVM data = MMenuRepo.getById(id);

            using (AppEntity db = new AppEntity())
            {
                m_menu item = db.m_menu.Find(id);

                item.is_active    = false;
                item.updated_by   = 1;
                item.updated_date = DateTime.Now;

                try
                {
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        public ActionResult Create(VMMenu paramModel)
        {
            try
            {
                MenuRepo.Message = string.Empty;

                //Create auto generate product_code
                using (var db = new Markom_IDLEEntities())
                {
                    string nol    = "";
                    m_menu cek    = db.m_menu.OrderByDescending(x => x.code).First();
                    int    simpan = int.Parse(cek.code.Substring(3));
                    simpan++;
                    for (int i = simpan.ToString().Length; i < 4; i++)
                    {
                        nol = nol + "0";
                    }
                    paramModel.code = "ME" + nol + simpan;
                }

                paramModel.created_by   = "Administrator";
                paramModel.created_date = DateTime.Now;
                paramModel.is_delete    = false;

                if (null == paramModel.name)
                {
                    MenuRepo.Message = "Anda belum memasukan semua data. Silahkan ulangi kembali";
                }
                if (string.IsNullOrEmpty(MenuRepo.Message))
                {
                    return(Json(new
                    {
                        success = MenuRepo.Insert(paramModel),
                        message = paramModel.code
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, message = MenuRepo.Message },
                                JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception hasError)
            {
                return(Json(new { success = false, message = hasError.Message },
                            JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 6
0
        public static Responses Update(M_MenuViewModel entity)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    if (entity.Id != 0)
                    {
                        m_menu menu = db.m_menu.Where(m => m.id == entity.Id && m.id != entity.ParentId).FirstOrDefault();
                        if (menu != null)
                        {
                            menu.code         = entity.Code;
                            menu.name         = entity.Name;
                            menu.controller   = entity.Controller;
                            menu.parent_id    = entity.ParentId;
                            menu.is_delete    = entity.IsDelete;
                            menu.updated_by   = "Soleh";
                            menu.updated_date = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        m_menu menu = new m_menu();
                        menu.code         = GetNewCode();
                        menu.name         = entity.Name;
                        menu.controller   = entity.Controller;
                        menu.parent_id    = entity.ParentId;
                        menu.is_delete    = false;
                        menu.created_by   = "Soleh";
                        menu.created_date = DateTime.Now;
                        db.m_menu.Add(menu);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }
Exemplo n.º 7
0
        // update
        public static bool Edit(MMenuVM model)
        {
            bool result = false;

            // simpan datanya ke model
            using (AppEntity db = new AppEntity())
            {
                // get data dari database
                m_menu item = db.m_menu.Find(model.id);
                item.id           = model.id;
                item.code         = model.code;
                item.name         = model.name;
                item.controller   = model.controller;
                item.parent_id    = model.parent_id;
                item.updated_by   = model.updated_by;
                item.updated_date = model.updated_date;
                try { db.SaveChanges(); result = true; }
                catch (Exception) { throw; }
            }
            return(result);
        }
Exemplo n.º 8
0
        public static string CreateMenu(MenuViewModel paramDataMenu)
        {
            string latestSaveCode = string.Empty;

            using (var db = new MarkomApplicationDBEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        m_menu c = new m_menu();
                        c.code        = MenuCode();
                        c.name        = paramDataMenu.name;
                        c.controller  = paramDataMenu.controller;
                        c.parent_id   = paramDataMenu.parentId;
                        c.is_delete   = paramDataMenu.isDelete;
                        c.create_by   = paramDataMenu.createBy;
                        c.create_date = paramDataMenu.createDate;

                        db.m_menu.Add(c);
                        db.SaveChanges();
                        dbContextTransaction.Commit();

                        //get latest save code
                        latestSaveCode = c.code;
                    }
                    catch (Exception ex)
                    {
                        Message = ex.Message;
                        dbContextTransaction.Rollback();
                        //throw;
                    }
                }
            }

            return(latestSaveCode);
        }
Exemplo n.º 9
0
        public static Responses Delete(int id)
        {
            Responses result = new Responses();

            try
            {
                using (var db = new MarcomContext())
                {
                    m_menu menu = db.m_menu.Where(m => m.id == id).FirstOrDefault();
                    if (menu != null)
                    {
                        menu.is_delete = true;

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                result.Success = false;
            }
            return(result);
        }