public ActionResult Edit([Bind(Include = "Id,Name,Username,Password,Email,RepeatPassword,Biography,IsPrivate")] User user, HttpPostedFileBase profilePictureFile)
        {
            if (!UserValidations.ValidateEmail(user.Email))
            {
                ViewBag.Error     = "Your email is invalid. Please enter a valid one.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidateUsername(user.Username))
            {
                ViewBag.Error     = "Your username is invalid. It should be between 3 and 50 characters long.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidatePassword(user.Password))
            {
                ViewBag.Error     = "Your password is invalid. It should be at least 8 characters long, contain at least one small and one big letter and one digit.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidateRepeatedPassword(user.Password, user.RepeatPassword))
            {
                ViewBag.Error     = "Your passwords do not match.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (!UserValidations.ValidateProfilePicture(profilePictureFile))
            {
                ViewBag.Error     = "You have not chosen a profile picture.";
                ViewBag.ShowError = true;
                return(View());
                //TODO: Add notification
            }

            if (ModelState.IsValid)
            {
                user.RegisterProfilePicture = PictureUtilities.PictureToByteArray(profilePictureFile);
                repo.Update(user);
                return(RedirectToAction("Details/" + AuthManager.GetAuthenticated().Id, "Users"));
            }
            return(View(user));
        }
        public ResultWrapper <PagedResult <UserOutDto> > GetAllUsersName(string name, int currentPage)
        {
            IEnumerable <ErrorResult> errors = userValid.ValidateUsername(name);

            if (errors.Count() > 0)
            {
                return(new ResultWrapper <PagedResult <UserOutDto> >(null, errors));
            }

            IQueryable <User> users = _unitOfWork.UserRepo.Find(user => user.Name.Contains(name));
            int pagesCount          = users.Count();
            int pageSize            = 25;

            users = users
                    .Skip((currentPage - 1) * pageSize)
                    .Take(25);

            var usersDto = Mapper.Map <IEnumerable <UserOutDto> >(users);
            PagedResult <UserOutDto> page = new PagedResult <UserOutDto>(currentPage, pagesCount, pageSize, usersDto);

            return(new ResultWrapper <PagedResult <UserOutDto> >(page, null));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Username,Password,Email,RepeatPassword,Biography,IsPrivate")] User user, HttpPostedFileBase profilePictureFile)
        {
            if (!UserValidations.ValidateEmail(user.Email))
            {
                ViewBag.Error     = "Your email is invalid. Please enter a valid one.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (UserUtilities.IsEmailTaken(user.Email, db))
            {
                ViewBag.Error     = "This email is already taken. Please register with another one.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidateUsername(user.Username))
            {
                ViewBag.Error     = "Your username is invalid. It should be between 3 and 50 characters long.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (UserUtilities.IsUserExisting(user.Username, db))
            {
                ViewBag.Error     = "This username is already taken. Please register with another one.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidatePassword(user.Password))
            {
                ViewBag.Error     = "Your password is invalid. It should be at least 8 characters long, contain at least one small and one big letter and one digit.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidateRepeatedPassword(user.Password, user.RepeatPassword))
            {
                ViewBag.Error     = "Your passwords do not match.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (!UserValidations.ValidateProfilePicture(profilePictureFile))
            {
                ViewBag.Error     = "You have not chosen a profile picture.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (ModelState.IsValid)
            {
                user.RegisterProfilePicture = PictureUtilities.PictureToByteArray(profilePictureFile);
                db.Users.Add(user);
                db.SaveChanges();
                AuthManager.SetCurrentUser(user.Username, user.Password);
                return(RedirectToAction("Details/" + AuthManager.GetAuthenticated().Id, "Users"));
            }
            return(View(user));
        }