Ejemplo n.º 1
0
        //validation
        protected bool ValidateUser(CreateEditUserViewModel validate)
        {
            if (String.IsNullOrWhiteSpace(validate.Editing.FirstName))
            {
                Validator.AddError("Editing.FirstName", "First name is required");
            }
            if (String.IsNullOrWhiteSpace(validate.Editing.LastName))
            {
                Validator.AddError("Editing.LastName", "Last name is required");
            }
            if (String.IsNullOrWhiteSpace(validate.Editing.UserType))
            {
                Validator.AddError("Editing.UserType", "User type is required");
            }
            if (validate.Editing.UserType != null && validate.Editing.UserType.ToLower().Equals("student") && String.IsNullOrWhiteSpace(validate.Editing.ClassInSchool))
            {
                Validator.AddError("Editing.ClassInSchool", "You must select a class in school for students");
            }
            if (validate.StaffID == 0)
            {
                Validator.AddError("Editing.StaffID", "Staff Creator is required");
            }

            return(Validator.IsValid);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(string userId)
        {
            var editUserViewModel = new CreateEditUserViewModel();

            editUserViewModel.UserDetails  = _userModel.GetDetails(userId);
            editUserViewModel.AllowedRoles = _userModel.GetAllRoles().ToList();

            return(View(editUserViewModel));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(CreateEditUserViewModel editing)
        {
            this.TryUpdateModel(editing);
            if (!Service.EditUser(editing))
            {
                return(View(new CreateEditUserViewModel(editing.Editing, Service.ListStaff(), Service.GetUserTypes())));
            }

            return(RedirectToAction("UserProfile", new { id = editing.Editing.UserID }));
        }
Ejemplo n.º 4
0
        public ActionResult UserIndex(CreateEditUserViewModel creating)
        {
            int ret = Service.CreateUser(creating);

            if (ret <= 0)//if an invalid user id is returned
            {
                return(View(new CreateEditUserViewModel(creating.Editing, Service.ListStaff(), Service.GetUserTypes())));
            }
            this.ShowMessage(MessageType.Success, creating.Editing.FirstName + " " + creating.Editing.LastName + " Created", true);
            return(RedirectToAction("UserProfile", new { id = ret }));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(int userId)
        {
            //look up a user in the db
            User user = usersRepository.Find(userId);
            CreateEditUserViewModel createView = new CreateEditUserViewModel();
            CompetenciesRepository compRepo = new CompetenciesRepository();
            CompetencyHeadersRepository headRepo = new CompetencyHeadersRepository();

            createView.User = user; 

            return View(createView);
        }
Ejemplo n.º 6
0
        //[Authorize](Roles="Admin")
        public ActionResult Create()
        {
            CreateEditUserViewModel vm = new CreateEditUserViewModel
            {
                User = new User(),
                CompetencyHeaders =
                    competencyHeadersRepository.AllIncluding(
                        a => a.Competencies).ToList()
            };

            return(View(vm));
        }
Ejemplo n.º 7
0
        public ActionResult Edit(int userId)
        {
            //look up a user in the db
            User user = usersRepository.Find(userId);
            CreateEditUserViewModel     createView = new CreateEditUserViewModel();
            CompetenciesRepository      compRepo   = new CompetenciesRepository();
            CompetencyHeadersRepository headRepo   = new CompetencyHeadersRepository();

            createView.User = user;

            return(View(createView));
        }
Ejemplo n.º 8
0
        public ActionResult Create(CreateEditUserViewModel user)
        {
            user.UserDetails.Roles = _userModel.GetRoles(user.SelectedRoles).ToList();

            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            _userModel.Create(user.UserDetails);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
        public ActionResult Create()
        {
            var createUserViewModel = new CreateEditUserViewModel
            {
                UserDetails = new UserDetailsViewModel
                {
                    User = new UserViewModel()
                },
                AllowedRoles = _userModel.GetAllRoles().ToList()
            };

            return(View(createUserViewModel));
        }
Ejemplo n.º 10
0
        public ActionResult Edit(CreateEditUserViewModel user)
        {
            user.UserDetails.Roles = _userModel.GetRoles(user.SelectedRoles).ToList();

            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            _userModel.Update(user.UserDetails);

            return(RedirectToAction("Details", new { userId = user.UserDetails.User.Id }));
        }
Ejemplo n.º 11
0
        //edit user by ID
        public bool EditUser(CreateEditUserViewModel editing)
        {
            // Validation logic
            if (!ValidateUser(editing))
            {
                return(false);
            }

            // Database logic
            try
            {
                User   staff   = Repository.GetUserByID(editing.StaffID);
                String creator = staff.FirstName + " " + staff.LastName;
                Repository.EditUser(editing.Editing, creator);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
        //create a user and insert user information to the database
        public int CreateUser(CreateEditUserViewModel creating)
        {
            int ret = -999;

            // Validation logic
            if (!ValidateUser(creating))
            {
                return(ret);
            }

            // Database logic
            try
            {
                User   staff   = Repository.GetUserByID(creating.StaffID);
                String creator = staff.FirstName + " " + staff.LastName;
                ret = Repository.CreateUser(creating.Editing, creator);
            }
            catch
            {
                return(-999);
            }
            return(ret);
        }
Ejemplo n.º 13
0
        //[Authorize](Roles="Admin")
        public ActionResult Create()
        {


            CreateEditUserViewModel vm = new CreateEditUserViewModel
                {
                    User = new User(),
                    CompetencyHeaders = 
                    competencyHeadersRepository.AllIncluding(
                        a => a.Competencies).ToList()
                };

            return View(vm);
        }