Пример #1
0
        public ActionResult EditUserTab(AddUserTabs data)
        {
            data.lstUsers = userDAL.GetAllUsers();
            if (ModelState.IsValid)
            {
                User_Tabs editedUser_Tab = db.User_Tabs.Find(data.ID);
                if (data.Username != editedUser_Tab.Username && db.User_Tabs.Any(w => w.Username == data.Username))
                {
                    TempData["ErrorMessage"] = "This username already exists";
                    return(View(data));
                }
                editedUser_Tab.Username        = data.Username;
                editedUser_Tab.TabIDs          = userDAL.GetTabIDsByNames(data.TabIDs);
                db.Entry(editedUser_Tab).State = EntityState.Modified;
                db.SaveChanges();
                TempData["InfoMessage"] = "User privileges has been successfully edited";
                return(RedirectToAction("UserTabs"));
            }

            return(View(data));
        }
Пример #2
0
        public ActionResult AddUserTab(AddUserTabs data)
        {
            data.lstUsers = userDAL.GetAllUsers();
            if (db.User_Tabs.Any(w => w.Username == data.Username))
            {
                TempData["ErrorMessage"] = "This username already exists";
                return(View(data));
            }
            if (ModelState.IsValid)
            {
                User_Tabs user_tab = new User_Tabs()
                {
                    Username = data.Username,
                    TabIDs   = userDAL.GetTabIDsByNames(data.TabIDs)
                };
                db.User_Tabs.Add(user_tab);
                db.SaveChanges();
                TempData["InfoMessage"] = "New user privileges has been successfully added";
                return(RedirectToAction("UserTabs"));
            }

            return(View(data));
        }