Exemple #1
0
        public ActionResult Delete(int?id, bool?saveChangesError = false)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (saveChangesError.GetValueOrDefault())
            {
                ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator.";
            }

            UserProfileTransferModel userProfileDto = _userProfileService.GetUserProfile(id);

            if (userProfileDto == null)
            {
                return(HttpNotFound());
            }

            var userProfile = Mapper.Map <UserProfileTransferModel, UserProfileDetailsViewModel>(userProfileDto);

            var direction = Mapper.Map <DirectionTransferModel, DirectionViewModel>(_directionService.GetDirection(userProfileDto.DirectionId));

            ViewBag.Direction = direction.Name;

            return(View(userProfile));
        }
        private void UserProfileValidation(UserProfileTransferModel userProfileDto, bool isUpdating)
        {
            var existUserProfiles = Database.UserProfiles.Find(up => up.Email == userProfileDto.Email);

            if (!(
                    (existUserProfiles.Count() == 0) ||
                    (existUserProfiles.Count() == 1 && isUpdating)
                    )
                )
            {
                throw new ValidationException($"User with the same Email already exist", nameof(userProfileDto.Email));
            }

            if (userProfileDto.MathScore > 10 || userProfileDto.MathScore < 0)
            {
                throw new ValidationException($"The MathScore value cannot be less than 0 and greater then 10",
                                              nameof(userProfileDto.MathScore));
            }
            if (userProfileDto.UniversityAverageScore > 10 || userProfileDto.UniversityAverageScore < 0)
            {
                throw new ValidationException($"The UniversityAverageScore value cannot be less than 0 and greater then 10",
                                              nameof(userProfileDto.UniversityAverageScore));
            }
            else
            {
                return;
            }
        }
        public void UpdateUserProfile(UserProfileTransferModel userProfileDto)
        {
            UserProfileValidation(userProfileDto, true);

            var userProfile = Database.UserProfiles.Get(userProfileDto.UserId);

            if (userProfile != null)
            {
                Mapper.Map(userProfileDto, userProfile);
                Database.Save();
            }
        }
Exemple #4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            UserProfileTransferModel userProfileDto = _userProfileService.GetUserProfile(id);

            if (userProfileDto == null)
            {
                return(HttpNotFound());
            }

            var userProfile = Mapper.Map <UserProfileTransferModel, UserProfileDetailsViewModel>(userProfileDto);

            ViewBag.DirectionId = GetDirections();

            return(View(userProfile));
        }
Exemple #5
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            UserProfileTransferModel userProfileDto = _userProfileService.GetUserProfile(id);

            if (userProfileDto == null)
            {
                return(HttpNotFound());
            }

            var userProfile = Mapper.Map <UserProfileTransferModel, UserProfileDetailsViewModel>(userProfileDto);

            var direction = Mapper.Map <DirectionTransferModel, DirectionViewModel>(_directionService.GetDirection(userProfileDto.DirectionId));

            ViewBag.Direction = direction.Name;

            return(View(userProfile));
        }
        public void SaveUserProfile(UserProfileTransferModel userProfileDto)
        {
            // Validation
            UserProfileValidation(userProfileDto, false);

            //try to create user in the Identity DB
            UserTransferModel userDto = Mapper.Map <UserProfileTransferModel, UserTransferModel>(userProfileDto);

            userDto.Role = "user";
            OperationDetails identityResult = userService.Create(userDto).Result;

            if (identityResult.Succedeed)
            {
                var userProfile = Mapper.Map <UserProfileTransferModel, UserProfile>(userProfileDto);
                Database.UserProfiles.Create(userProfile);
                Database.Save();
            }
            else
            {
                throw new ValidationException(identityResult.Message, userProfileDto.Email); //return message from Create() method of UserService
            }
        }