Beispiel #1
0
        public ActionResult Create(Entities.User obj)
        {
            //ModelState.Remove("class.property");
            if (_objUser.Validate(obj, "insert"))
            {
                TempData["Msg"] = "Email address already exist.";
                // ModelState.AddModelError("User.Email", "Email address already exist.");
                // return RedirectToAction("Create");

                // Roles List
                //ViewBag.RoleList = new SelectList(_objRole.SelectList((int) Session["UID"]), "RoleId", "Name", null);

                // Managers List - Add 6/2/2016
                // ViewBag.ManagerList = new SelectList(_objRole.ManagersList(), "Uid", "Name", null);

                return(RedirectToAction("Create"));// View();
            }

            try
            {
                obj.ManagerId = User.IsInRole("Admin") ? obj.ManagerId > 0 ? obj.ManagerId : 0 : (int)Session["UID"];
                _objUser.Create(obj);

                TempData["Msg"] = "New users has been created.";
                return(RedirectToAction("Create"));
            }
            catch (Exception exception)
            {
                // log error
                Business.Services.LogError.Insert(exception, (int)Session["UID"]);

                TempData["Msg"] = "Error: " + exception.Message;
                return(RedirectToAction("Create"));// View();
            }
        }
Beispiel #2
0
        public ActionResult Edit(Entities.User obj, int page)
        {
            try
            {
                //ModelState.Remove("class.property");
                if (_objUser.Validate(obj, "update"))
                {
                    TempData["Msg"] = "Email address already exist.";
                    return(RedirectToAction("Edit"));
                }

                _objUser.Update(obj);

                if (User.IsInRole("Admin"))
                {
                    Entities.UsersPassword usersPassword = new Entities.UsersPassword();
                    var objUsersPassword = _objUserPassword.Select(obj.Uid);

                    if (objUsersPassword != null)
                    {
                        objUsersPassword.Password = obj.Password;
                        objUsersPassword.Uid      = obj.Uid;
                        _objUserPassword.Update(objUsersPassword);
                    }

                    // UsersManager - Added 6/6/2016
                    {
                        Entities.UsersManager objUsersManager = new UsersManager();
                        objUsersManager.ManagerId = (int)obj.ManagerId;
                        objUsersManager.Uid       = obj.Uid;

                        Business.Interfaces.IUserManager userManager = new UserManager();
                        userManager.AddorUpdate(objUsersManager);
                    }
                }

                TempData["Msg"] = "User updated successfully.";

                //RedirectToLocal(page.ToString(), "Edit");
                return(RedirectToAction("Edit", new { page = page }));
            }
            catch (Exception exception)
            {
                // log error
                Business.Services.LogError.Insert(exception, (int)Session["UID"]);

                TempData["Msg"] = "Error: " + exception.Message;
                return(RedirectToAction("Edit"));
            }
        }