Пример #1
0
        public ActionResult Create([Bind(Include = "Id,UserId,Description,Content")] CreatePictureViewModel picture, string tags, HttpPostedFileBase ContentFile)
        {
            if (ContentFile == null)
            {
                ViewBag.Error     = "You have not chosen a picture.";
                ViewBag.ShowError = true;
                return(View());
            }

            if (ModelState.IsValid)
            {
                var tagsList      = tags.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                var currentUserId = AuthManager.GetAuthenticated().Id;
                var description   = picture.Description;
                var contentFile   = ContentFile;

                var content       = PictureUtilities.PictureToByteArray(contentFile);
                var pictureEntity = new Picture()
                {
                    Content     = content,
                    Description = description,
                    UserId      = currentUserId
                };
                pictureEntity = TagsController.Create(tagsList, pictureEntity, db);
                db.Pictures.Add(pictureEntity);
                db.SaveChanges();
                return(RedirectToAction("Details/" + currentUserId, "Users"));
            }
            return(View(picture));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }