public ProcessResult EditStudent(Student newStudent,
            HttpServerUtilityBase server,
            HttpPostedFileBase imageUpload)
        {
            var studentToEdit = entities.Students.FirstOrDefault(x => x.Id == newStudent.Id);
            if (studentToEdit == null)
                return ProcessResults.ErrorOccured;

            studentToEdit.Login = newStudent.Login;
            studentToEdit.Name = newStudent.Name;
            if (!String.IsNullOrEmpty(newStudent.Password))
                studentToEdit.Password = Security.GetHashString(newStudent.Password);
            studentToEdit.Email = newStudent.Email;
            studentToEdit.LastName = newStudent.LastName;
            if (imageUpload != null)
            {
                if (imageUpload.ContentLength <= 0 || !Security.IsImage(imageUpload))
                    return ProcessResults.InvalidImageFormat;

                if (studentToEdit.ImgSrc != null)
                    DeleteImage(studentToEdit.ImgSrc, server);
                studentToEdit.ImgSrc = SaveImage(studentToEdit.Id,
                    StaticSettings.AvatarsUploadFolderPath,
                    studentToEdit.Email,
                    imageUpload,
                    server);
            }
            else if (!String.IsNullOrEmpty(studentToEdit.ImgSrc))
            {
                DeleteImage(studentToEdit.ImgSrc, server);
                studentToEdit.ImgSrc = null;
            }

            SaveChanges();
            return ProcessResults.EditedSuccessfully;
        }
 public void UpdateLastVisitDate(Student student)
 {
     student.LastVisitDate = DateTime.Now;
     SaveChanges();
 }
        public ActionResult ManageStudentEditing(string Id, string Name,
        string LastName, string Login,
        string Email, string Password,
        HttpPostedFileBase imageUpload)
        {
            var lecturer = new Student()
            {
                Id = Convert.ToInt32(Id),
                Name = Name,
                Login = Login,
                Email = Email,
                Password = Password,
                LastName = LastName
            };

            ProcessResult p = DataManager.Student.EditStudent(lecturer, Server, imageUpload);
            return RedirectToAction("Index", "Home", new { result = p.Id });
        }
        public ProcessResult RegistrateStudent(
            HttpContextBase context,
            Student student,
            HttpServerUtilityBase server,
            HttpPostedFileBase imageUpload)
        {
            Func<Student, bool> func = x => x.Email == student.Email && x.Login == student.Login;
            var exists = GetStudent(func);
            student.Password = Security.GetHashString(student.Password);
            student.Activation = (int)UserStatus.Unconfirmed;
            if (exists != null)
                return ProcessResults.UserAlreadyExists;

            if (imageUpload != null)
            {
                if (imageUpload.ContentLength <= 0 || !Security.IsImage(imageUpload))
                    return ProcessResults.InvalidImageFormat;

                student.ImgSrc = SaveImage(student.Id,
                    StaticSettings.AvatarsUploadFolderPath,
                    student.Email,
                    imageUpload,
                    server);
            }

            if (!SendConfirmationMail(context, student.Email, student.Password, UserType.Student.ToString()))
                return ProcessResults.ErrorOccured;
            student.LastVisitDate = DateTime.Now;
            student.RegDate = DateTime.Now;
            var st = entities.Students.Add(student);
            SaveChanges();
            return ProcessResults.RegistrationCompleted;
        }