Beispiel #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));
        }
Beispiel #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 }));
        }
Beispiel #3
0
        public ActionResult Login(string username, string password)
        {
            Student.Models.ApplicationDbContext dbContext = Student.Models.ApplicationDbContext.Create();

            Student.Models.User userModel = new Student.Models.User();

            List <Student.Models.User> list = dbContext.Users.Where(m => m.Username == username && m.Password == password).ToList();

            if (list.Count() != 0)
            {
                var uid = list[0].ID;

                var role = dbContext.Roles.Where(r => r.UserID == uid).ToList();

                dbContext.Dispose();

                Session.Timeout   = 60;
                Session["Logged"] = true;
                Session["Name"]   = list[0].FirstName + " " + list[0].LastName;
                Session["ID"]     = list[0].ID;
                switch (role[0].Role)
                {
                case Student.Models.UserRole.roles.student:
                    Session["Role"] = "student";
                    break;

                case Student.Models.UserRole.roles.professor:
                    Session["Role"] = "prof";
                    break;

                case Student.Models.UserRole.roles.administrator:
                    Session["Role"] = "admin";
                    break;
                }
                ViewBag.message = "";

                return(RedirectToAction("Index", "Project"));
            }
            else
            {
                ViewBag.message = "Wrong username or password!";
            }

            return(View("Login"));
        }
Beispiel #4
0
        public ActionResult DownloadProject(int projectId, int userId)
        {
            Student.Models.ApplicationDbContext db = Student.Models.ApplicationDbContext.Create();

            var userProj = db.UsersProjects.Where(up => up.ProjectID == projectId && up.UserID == userId).ToList()[0];

            Response.Clear();
            MemoryStream ms        = new MemoryStream(userProj.File);
            var          extension = userProj.FileExtension;

            Response.ContentType = GetMIMEType(extension);
            Response.AddHeader("content-disposition", "attachment;filename=Project");
            Response.Buffer = true;
            ms.WriteTo(Response.OutputStream);
            Response.End();

            db.Dispose();
            return(RedirectToAction("ViewProject", "Project", new { ID = projectId }));
        }
Beispiel #5
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"));
            }
        }