Пример #1
0
        public UserListingModel GetUserListing(UserFilterModel filter)
        {
            if (filter == null) filter = new UserFilterModel();

            var query = Mapper.Map<UserFilterModel, Data.Query.UserQuery>(filter);
            var users = SecurityRepository.GetUsers(query).OrderBy(o => o.Name).ToList();
            var userList = Mapper.Map<List<Data.Graph.Employee>, IList<UserModel>>(users);

            UserListingModel model = new UserListingModel();
            model.Filter = filter;
            model.UserList = userList.ToPagedList(filter.Page, filter.Size);

            return model;
        }
        // TODO: test?
        public ActionResult UserListing(UserFilterModel filter)
        {
            var listing = EmployeeServices.GetUserListing(filter);
            listing.Filter = filter;
            ViewBag.SizeOptions = LookupServices.GetSizeOptions(filter.Size);
            ViewBag.SiteAccessOptions = LookupServices.GetSiteAccessOptions(filter.HasSiteAccess, true);
            ViewBag.RoleOptions = LookupServices.GetRoleOptions(filter.Role, true);

            if (listing.UserList.Count == 0)
                return View("UserListingNoData", listing);
            else
                return View("UserListing", listing);
        }
        public ActionResult NewUser(UserModel user, UserFilterModel filter)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    EmployeeServices.CreateUser(user);
                    return RedirectToAction("UserListing", filter.GenerateUserAccessRoute());
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
                ModelState.AddModelError(String.Empty, Constants.ServerError);
            }

            // Invalid - redisplay with errors
            var model = new UserDetailModel()
            {
                Action = "NewUser",
                User = user,
                Filter = filter,
                Roles = LookupServices.GetRoleOptions(user.RoleName)
            };

            ViewBag.Locations = LocationServices.GetLocationLookup(true, -1);
            return View("UserDetail", model);
        }
        public ActionResult NewUser(UserFilterModel filter)
        {
            var model = new UserDetailModel()
            {
                Action = "NewUser",
                User = new UserModel(),
                Filter = filter,
                Roles = LookupServices.GetRoleOptions("Employee")
            };
            model.User.PasswordString = PasswordGenerator.GeneratePassword();

            ViewBag.Locations = LocationServices.GetLocationLookup(true, -1);
            return View("UserDetail", model);
        }
        public ActionResult EditUser(int id, UserFilterModel filter, FormCollection collection)
        {
            var user = EmployeeServices.GetUser(id);

            try
            {
                UpdateModel(user, "User");
                EmployeeServices.UpdateUser(user);

                return RedirectToAction("UserListing", filter.GenerateUserAccessRoute());
            }
            catch (Exception ex)
            {
                // Invalid - redisplay with errors
                Logger.Error(ex.ToString());
                ModelState.AddModelError(String.Empty, Constants.ServerError);
                var model = new UserDetailModel()
                {
                    Action = "EditUser",
                    User = user,
                    Filter = filter,
                    Roles = LookupServices.GetRoleOptions(user.RoleName)
                };

                ViewBag.Locations = LocationServices.GetLocationLookup(true, model.User.LocationId);
                return View("UserDetail", model);
            }
        }
        public ActionResult EditUser(int id, UserFilterModel filter)
        {
            var user = EmployeeServices.GetUser(id);

            var model = new UserDetailModel()
            {
                Action = "EditUser",
                User = user,
                Filter = filter,
                Roles = LookupServices.GetRoleOptions(user.RoleName)
            };

            ViewBag.Locations = LocationServices.GetLocationLookup(true, model.User.LocationId);
            return View("UserDetail", model);
        }