Ejemplo n.º 1
0
        public ActionResult Create(user_rightViewModel user_right)
        {
            if (ModelState.IsValid)
            {
                foreach (var mn in user_right.ms_menus)
                {
                    ms_user_rights rights = new ms_user_rights()
                    {
                        user_rights_id = user_right.user_type.user_type_id,
                        job_level_id   = user_right.job_level.job_level_id,
                        menu_id        = mn.menu_id,
                        fl_active      = true,
                        created_date   = DateTime.Now,
                        created_by     = 0,
                        updated_date   = DateTime.Now,
                        updated_by     = 1,
                        deleted_date   = null,
                        deleted_by     = null,
                        org_id         = 0
                    };

                    db.ms_user_rights.Add(rights);
                    db.SaveChanges();
                }
            }

            //ViewBag.job_level_id = new SelectList(db.ms_job_level, "job_level_id", "job_level_code", user_right.job_level.job_level_id);
            //ViewBag.user_type_id = new SelectList(db.ms_user_type, "user_type_id", "user_type_code", user_right.user_type.user_type_id);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public ActionResult PopulateForm(int?job_level = 0, int?user_type = 0)
        {
            job_level = (job_level == null || job_level <= 0) ? 0 : job_level;
            user_type = (user_type == null || user_type <= 0) ? 0 : user_type;

            user_rightViewModel _model = null;

            //check apakah update mode or new mode
            if (job_level > 0 && user_type > 0)
            {
                List <ms_user_rights> _list = db.ms_user_rights
                                              .Where(m => m.fl_active == true &&
                                                     m.deleted_date == null &&
                                                     m.user_type_id == user_type &&
                                                     m.job_level_id == job_level)
                                              .ToList <ms_user_rights>();

                if (_list.Count == 0) //----this is new  karena gak ketemu
                {
                    //new

                    _model                = new user_rightViewModel();
                    _model.FormMode       = EnumFormModeKey.Form_New;
                    _model.job_level_list = db.ms_job_level.Where(r => r.fl_active == true && r.deleted_date == null).ToList <ms_job_level>();
                    _model.user_type_list = db.ms_user_type.Where(r => r.fl_active == true && r.deleted_date == null).ToList <ms_user_type>();
                    _model.ms_menus       = db.ms_menu.Where(m => m.fl_active == true && m.deleted_date == null).ToList <ms_menu>();
                    foreach (var m in _model.ms_menus)
                    {
                        _model.checkbox_menu_id.Add(new SelectedMenu_CheckBoxes()
                        {
                            Checked = false,
                            menu_id = m.menu_id,
                            ms_menu = m,
                            Text    = m.menu_name,
                            Value   = m.menu_id.ToString()
                        });
                    }
                }
                else //sudah ada record = edit  mode
                {
                    _model                = new user_rightViewModel();
                    _model.FormMode       = EnumFormModeKey.Form_Edit;
                    _model.job_level_id   = (int)job_level;
                    _model.user_type_id   = (int)user_type;
                    _model.job_level_list = db.ms_job_level.Where(r => r.fl_active == true && r.deleted_date == null).ToList <ms_job_level>();
                    _model.user_type_list = db.ms_user_type.Where(r => r.fl_active == true && r.deleted_date == null).ToList <ms_user_type>();
                    _model.ms_menus       = db.ms_menu.Where(m => m.fl_active == true && m.deleted_date == null).ToList <ms_menu>();
                    int _i = 0;
                    foreach (var m in _model.ms_menus)
                    {
                        Boolean          _boolChecked = false;
                        ms_user_rights[] _res         = (from t1 in _list
                                                         where t1.job_level_id == (int)job_level &&
                                                         t1.user_type_id == (int)user_type &&
                                                         t1.menu_id == (int)m.menu_id
                                                         select t1).ToArray();
                        _boolChecked = (_res.Length > 0);
                        if (_boolChecked)
                        {
                            _i++;
                        }
                        _model.checkbox_menu_id.Add(new SelectedMenu_CheckBoxes()
                        {
                            Checked = _boolChecked,
                            menu_id = m.menu_id,
                            ms_menu = m,
                            Text    = m.menu_name,
                            Value   = m.menu_id.ToString()
                        });
                    }
                }
            }
            else
            {
                //new
                _model                = new user_rightViewModel();
                _model.FormMode       = EnumFormModeKey.Form_New;
                _model.job_level_list = db.ms_job_level.Where(r => r.fl_active == true && r.deleted_date == null).ToList <ms_job_level>();
                _model.user_type_list = db.ms_user_type.Where(r => r.fl_active == true && r.deleted_date == null).ToList <ms_user_type>();
                _model.ms_menus       = db.ms_menu.Where(m => m.fl_active == true && m.deleted_date == null).ToList <ms_menu>();
                foreach (var m in _model.ms_menus)
                {
                    _model.checkbox_menu_id.Add(new SelectedMenu_CheckBoxes()
                    {
                        Checked = false,
                        menu_id = m.menu_id,
                        ms_menu = m,
                        Text    = m.menu_name,
                        Value   = m.menu_id.ToString()
                    });
                }
            }

            //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 = (int)job_level,
            //    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.OrderBy(c=>c.Value);

            //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 = (int)user_type,
            //    user_type_code = "Select",
            //    user_type_name = "-- Select User Right --"
            //};
            //ds_user_type.Add(ut_opt);
            //SelectList user_type_ddl = new SelectList(ds_user_type, "user_type_id", "user_type_name");
            //ViewBag.user_type_id = user_type_ddl;

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