public ProcessResult EditLecturer(Lecturer newLecturer,
            HttpServerUtilityBase server,
            HttpPostedFileBase imageUpload)
        {
            var lecturerToEdit = entities.Lecturers.FirstOrDefault(x => x.Id == newLecturer.Id);
            if (lecturerToEdit == null)
                return ProcessResults.ErrorOccured;

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

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

            SaveChanges();
            return ProcessResults.EditedSuccessfully;
        }
        public ProcessResult RegistrateLecturer(
            HttpContextBase context,
            Lecturer lecturer,
            HttpServerUtilityBase server,
            HttpPostedFileBase imageUpload)
        {
            Func<Lecturer, bool> func = x => x.Email == lecturer.Email;
            var exists = GetLecturer(func);
            lecturer.Password = Security.GetHashString(lecturer.Password);
            lecturer.Activation = (int)UserStatus.Unconfirmed;
            if (exists != null)
                return ProcessResults.UserAlreadyExists;

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

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

            if (!SendConfirmationMail(context,
                lecturer.Email,
                lecturer.Password,
                UserType.Lecturer.ToString()))
                return ProcessResults.ErrorOccured;

            lecturer.LastVisitDate = DateTime.Now;

            var st = entities.Lecturers.Add(lecturer);
            SaveChanges();
            return ProcessResults.RegistrationCompleted;
        }
 public void UpdateLastVisitDate(Lecturer lecturer)
 {
     if (lecturer == null)
         return;
     lecturer.LastVisitDate = DateTime.Now;
     SaveChanges();
 }
        public ActionResult ManageLecturerRegistration(
            string Name, string LastName, string Login,
            string Email, string Password, string Subject,
            string Position, HttpPostedFileBase imageUpload)
        {
            var registrationModel = new Lecturer()
            {
                Name = Name,
                LastName = LastName,
                Login = Login,
                Password = Password,
                DepartmentId = 1,
                Faculty = "КН",
                Email = Email,
                Subject = Subject,
                Position = Position
            };

            ProcessResult result = DataManager.
                Lecturer.
                RegistrateLecturer(HttpContext,
                registrationModel,
                Server,
                imageUpload);

            return RedirectToAction("Registration", "User", new { result = result.Id });
        }
        public ActionResult ManageLecturerEditing(string Id, string Name,
            string LastName, string Login,
            string Email, string Password,
            HttpPostedFileBase imageUpload)
        {
            var lecturer = new Lecturer()
            {
                Id = Convert.ToInt32(Id),
                Name = Name,
                Login = Login,
                Email = Email,
                Password = Password,
                LastName = LastName
            };

            ProcessResult p = DataManager.Lecturer.EditLecturer(lecturer, Server, imageUpload);
            return RedirectToAction("Index", "Home", new { result = p.Id });
        }