Ejemplo n.º 1
0
        //
        // GET: /User/Add
        public ActionResult Add()
        {
            try
            {
                var roles = _db.Roles.ToList().Select(x => new AssignRoleModel { RoleName = x.RoleName });

                var userViewModel = new UserViewModel { Roles = roles };

                return PartialView("_Add", userViewModel);
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return RedirectToAction("Index", "User");
            }
        }
Ejemplo n.º 2
0
        public ActionResult Add(UserViewModel viewModel, string[] RoleName)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CreateUserWithRole(viewModel.UserName, viewModel.Password, viewModel.Email, RoleName);

                    return Content(Boolean.TrueString);
                }

                return Content(ExceptionHelper.ModelStateErrorFormat(ModelState));
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return Content("Sorry! Unable to add this user.");
            }
        }
Ejemplo n.º 3
0
        //
        // GET: /User/Details/By ID
        public ActionResult Details(string id)
        {
            try
            {
                var user = _db.Users.Find(id);
                if (user != null)
                {
                    var roles = user.Roles.ToList().Select(x => new AssignRoleModel { RoleName = x.RoleName });

                    var userViewModel = new UserViewModel { UserName = user.UserName, Email = user.Email, Roles = roles };

                    //return View(userViewModel);
                    return PartialView("_Details", userViewModel);
                }
                else
                {
                    return RedirectToAction("Index", "User");
                }

            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return RedirectToAction("Index", "User");
            }
        }
Ejemplo n.º 4
0
        //
        // GET: /User/Delete/By ID
        public ActionResult Delete(string id)
        {
            try
            {
                var user = _db.Users.Find(id);
                if (user != null)
                {
                    var userViewModel = new UserViewModel { UserName = user.UserName, Email = user.Email };

                    return PartialView("_Delete", userViewModel);
                }
                else
                {
                    return RedirectToAction("Index", "User");
                }

            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionMessageFormat(ex, true);
                return RedirectToAction("Index", "User");
            }
        }