예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
예제 #3
0
 public void UpdateLastVisitDate(Lecturer lecturer)
 {
     if (lecturer == null)
         return;
     lecturer.LastVisitDate = DateTime.Now;
     SaveChanges();
 }
예제 #4
0
        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 });
        }
예제 #5
0
        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 });
        }