Exemplo n.º 1
0
        public JsonResult PackDelete(int id)
        {
            ms_menu _o = db.ms_menu.Find(id);

            db.ms_menu.Remove(_o);
            db.SaveChanges();
            return(Json("Records deleted successfully.", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            ms_menu ms_menu = db.ms_menu.Find(id);

            db.ms_menu.Remove(ms_menu);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "menu_id,menu_code,menu_name,module_id,fl_active,created_date,created_by,updated_date,updated_by,deleted_date,deleted_by,org_id,menu_url,rec_order")] ms_menu ms_menu)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ms_menu).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ms_menu));
 }
Exemplo n.º 4
0
        // GET: menu/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ms_menu ms_menu = db.ms_menu.Find(id);

            if (ms_menu == null)
            {
                return(HttpNotFound());
            }
            return(View(ms_menu));
        }
Exemplo n.º 5
0
        public JsonResult CRUDMenu()
        {
            if (Request.HttpMethod == "POST")
            {
                ms_menu _o = null;
                int     id = 0;
                switch (Request.Form["oper"])
                {
                case "del":
                    string   ids    = Request.Form["id"];
                    string[] values = ids.Split(',');
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = values[i].Trim();
                        //prepare for soft delete data
                        id                 = Convert.ToInt32(values[i]);
                        _o                 = db.ms_menu.Find(id);
                        _o.fl_active       = false;
                        _o.deleted_by      = UserProfile.UserId; //userid
                        _o.deleted_date    = DateTime.Now;
                        db.Entry(_o).State = EntityState.Modified;
                        db.SaveChanges();
                        db.SaveChanges();
                    }
                    break;

                case "add":
                    _o           = new ms_menu();
                    _o.module_id = Convert.ToInt32(Request.Form["module_name"]);
                    _o.menu_code = Request.Form["menu_code"];
                    _o.menu_name = Request.Form["menu_name"];
                    _o.menu_url  = Request.Form["menu_url"];
                    _o.fl_active = Request.Form["fl_active"].ToLower().Equals("yes");
                    _o.rec_order = Convert.ToInt32(Request.Form["rec_order"]);

                    _o.created_by      = UserProfile.UserId;
                    _o.created_date    = DateTime.Now;
                    _o.updated_by      = UserProfile.UserId;
                    _o.updated_date    = DateTime.Now;
                    _o.org_id          = UserProfile.OrgId;
                    _o.deleted_by      = null;
                    _o.deleted_date    = null;
                    db.Entry(_o).State = EntityState.Added;
                    db.SaveChanges();
                    break;

                case "edit":
                    bool boolNumeric = Int32.TryParse(Request.Form["menu_id"], out id);
                    if (boolNumeric)         //update
                    {
                        _o           = db.ms_menu.Find(id);
                        _o.module_id = Convert.ToInt32(Request.Form["module_name"]);
                        _o.menu_code = Request.Form["menu_code"];
                        _o.menu_name = Request.Form["menu_name"];
                        _o.menu_url  = Request.Form["menu_url"];
                        _o.fl_active = Request.Form["fl_active"].ToLower().Equals("yes");
                        _o.rec_order = Convert.ToInt32(Request.Form["rec_order"]);

                        _o.updated_by      = UserProfile.UserId;
                        _o.updated_date    = DateTime.Now;
                        _o.org_id          = UserProfile.OrgId;
                        _o.deleted_by      = null;
                        _o.deleted_date    = null;
                        db.Entry(_o).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else      //add
                    {
                        _o           = new ms_menu();
                        _o.module_id = Convert.ToInt32(Request.Form["module_name"]);
                        _o.menu_code = Request.Form["menu_code"];
                        _o.menu_name = Request.Form["menu_name"];
                        _o.menu_url  = Request.Form["menu_url"];
                        _o.fl_active = Request.Form["fl_active"].ToLower().Equals("yes");
                        _o.rec_order = Convert.ToInt32(Request.Form["rec_order"]);

                        _o.created_by      = UserProfile.UserId;
                        _o.created_date    = DateTime.Now;
                        _o.updated_by      = UserProfile.UserId;
                        _o.updated_date    = DateTime.Now;
                        _o.org_id          = UserProfile.OrgId;
                        _o.deleted_by      = null;
                        _o.deleted_date    = null;
                        db.Entry(_o).State = EntityState.Added;
                        db.SaveChanges();
                    }
                    break;

                default:
                    break;
                }
                return(Json("Records successfully saved.", JsonRequestBehavior.AllowGet));
            }
            return(Json("Invalid requests"));
        }
Exemplo n.º 6
0
        public ActionResult Create(user_rightViewModel user_right)
        {
            string _ids = Request.Form["menu_id"];

            if (string.IsNullOrWhiteSpace(_ids))
            {
                user_right.selected_menu_id_str = "0,0";
            }
            else
            {
                user_right.selected_menu_id_str = _ids;
            }

            if (ModelState.IsValid)
            {
                ms_user_rights[] _objs = (from m in db.ms_user_rights
                                          where m.job_level_id == user_right.job_level_id &&
                                          m.user_type_id == user_right.user_type_id
                                          select m).ToArray();
                if (_objs.Length > 0)
                {
                    IEnumerable <ms_user_rights> _ur = db.ms_user_rights.RemoveRange(_objs);
                    db.SaveChanges();
                }
                ms_user_type user_type_db = db.ms_user_type.Single(u => u.user_type_id == user_right.user_type_id);
                if (user_type_db == null)
                {
                    throw new Exception("Unknown User Right");
                }
                ms_job_level job_level_db = db.ms_job_level.Single(u => u.job_level_id == user_right.job_level_id);
                if (job_level_db == null)
                {
                    throw new Exception("Unknown Job Level");
                }

                string[] arr_menu_id = user_right.selected_menu_id_str.Split(new char[1] {
                    ','
                });
                bool bool_menu    = false;
                int  menu_counter = 0;
                foreach (var menu_id_string in arr_menu_id)
                {
                    int     menu_id_int = Convert.ToInt32(menu_id_string);
                    ms_menu menu_db     = db.ms_menu.Single(m => m.menu_id == menu_id_int);
                    bool_menu = (menu_db != null);
                    if (bool_menu)
                    {
                        menu_counter++;
                        ms_user_rights rights = new ms_user_rights()
                        {
                            user_type_id = user_right.user_type_id,
                            job_level_id = user_right.job_level_id,
                            menu_id      = menu_id_int,

                            fl_active = true,

                            created_date = DateTime.Now,
                            created_by   = UserProfile.UserId,

                            updated_date = DateTime.Now,
                            updated_by   = UserProfile.UserId,

                            deleted_date = null,
                            deleted_by   = null,
                            org_id       = UserProfile.OrgId
                        };
                        db.ms_user_rights.Add(rights);
                    }
                }
                if (menu_counter > 0)
                {
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            List <ms_job_level> ds_job = db.ms_job_level.Where(m => m.fl_active == true && m.deleted_date == null).ToList();
            ms_job_level        jl_opt = new ms_job_level
            {
                job_level_id   = 0,
                job_level_code = "Select",
                job_level_name = "-- Select Job Level --"
            };

            ds_job.Add(jl_opt);
            var job_level_ddl = new SelectList(ds_job, "job_level_id", "job_level_name", jl_opt);

            ViewBag.job_level_id = job_level_ddl;

            List <ms_user_type> ds_user_type = db.ms_user_type.Where(m => m.fl_active == true && m.deleted_date == null).ToList();
            ms_user_type        ut_opt       = new ms_user_type
            {
                user_type_id   = 0,
                user_type_code = "Select",
                user_type_name = "-- Select User Right --"
            };

            ds_user_type.Add(ut_opt);
            var user_type_ddl = new SelectList(ds_user_type, "user_type_id", "user_type_name", ut_opt);

            ViewBag.user_type_id = user_type_ddl;

            //ViewBag.job_level_id = new SelectList(db.ms_job_level, "job_level_id", "job_level_name", user_right.job_level_id);
            //ViewBag.user_type_id = new SelectList(db.ms_user_type, "user_type_id", "user_type_name", user_right.user_type_id);

            return(View("Create", user_right));
        }