Exemple #1
0
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            Student.Models.ApplicationDbContext db = Student.Models.ApplicationDbContext.Create();

            var uid = (int)Session["ID"];

            var edit = db.Users.SingleOrDefault(u => u.ID == uid);

            if (edit.Password != model.OldPassword)
            {
                ViewBag.passerror = "Incorrect password.";
            }
            else
            {
                if (model.NewPassword == model.ConfirmPassword)
                {
                    edit.Password = model.NewPassword;

                    db.SaveChanges();

                    ViewBag.passerror = "";

                    return(RedirectToAction("Settings"));
                }
                else
                {
                    ViewBag.passerror = "The new password and confirmation password do not match.";
                }
            }

            db.Dispose();
            return(View("Settings", model));
        }
Exemple #2
0
        public ActionResult SubmitProject(SubmitModel submitModel, int projectId, int userId)
        {
            if (!ModelState.IsValid)
            {
                return(View(submitModel));
            }

            byte[] uploadedFile = new byte[submitModel.File.InputStream.Length];
            string fileName     = submitModel.File.FileName.ToString();
            var    index        = fileName.LastIndexOf(".");
            string extension    = fileName.Substring(index + 1, fileName.Length - index - 1);

            submitModel.File.InputStream.Read(uploadedFile, 0, uploadedFile.Length);

            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            var file = dbContext.UsersProjects.SingleOrDefault(up => up.ProjectID == projectId && up.UserID == userId);

            file.File          = uploadedFile;
            file.FileName      = submitModel.File.FileName.ToString();
            file.FileExtension = extension;

            dbContext.SaveChanges();

            dbContext.Dispose();
            return(RedirectToAction("ViewProject", "Project", new { ID = projectId }));
        }
Exemple #3
0
        public ActionResult EditProfile(EditProfileViewModel model)
        {
            bool err = false;

            if (!validateCNP(model.CNP))
            {
                ViewBag.cnperror = "Invalid CNP.";
                err = true;
            }

            if (!validateEmail(model.Email))
            {
                ViewBag.emailerror = "Invalid email.";
                err = true;
            }

            if (err)
            {
                return(View("Profile", model));
            }
            else
            {
                Student.Models.ApplicationDbContext db = Student.Models.ApplicationDbContext.Create();

                var uid = (int)Session["ID"];

                var edit = db.Users.SingleOrDefault(u => u.ID == uid);

                edit.FirstName = model.FirstName;
                edit.LastName  = model.LastName;
                edit.CNP       = model.CNP;
                edit.Email     = model.Email;

                db.SaveChanges();
                db.Dispose();

                return(RedirectToAction("Profile"));
            }
        }