public ActionResult EditCourse(CourseViewModel course) { if (ModelState.IsValid) { var c = _coursesProvider.GetCourse(course.Id); var template = _templatesProvider.GetTemplate(course.Template.Value); Employee manager = null; if (course.Keeper.HasValue) { manager = _employeesProvider.GetEmployee(course.Keeper.Value); } c.Name = course.Name; c.SetTemplate(template); _courseUpdater.Update(c); if ((c.Manager == null && course.Keeper.HasValue) || (c.Manager != null && c.Manager.Id != course.Keeper) || (c.Manager != null && c.Manager == null)) { _courseUpdater.SetManager(c, manager); } } return(RedirectToAction("Index")); }
public ActionResult Add(StudentViewModel student) { if (ModelState.IsValid) { var course = _coursesProvider.GetCourse(student.Course); var mode = _modesProvider.GetModes().Single(n => n.Id == student.Mode); _studentCreator.Create(student.Name, student.LastName, student.Album, course, mode, student.Email, student.Phone, student.City, student.Street, student.PostalCode); return(Json(true)); } return(PartialView("Partials/_FormSubmitResult", ModelState)); }
public ActionResult Add(CreateEmployeeViewModel e) { if (ModelState.IsValid) { var course = _coursesProvider.GetCourse(e.Course); EmployeeCreateStatus status; var employee = _employeeCreator.Create(e.UserName, e.FirstName, e.LastName, e.Password, e.Email, e.Question, e.Answer, e.Moderator, e.SuperAdministrator, e.Administrator, course, out status); if (status == EmployeeCreateStatus.Success) { string message = string.Format("Twoje konto w systemie SOPS zostało utworzone\n Nazwa użytkownika: {0}\n Hasło: {1}\nPytanie do resetowania hasła: {2}\nOdpowiedź: {3}", e.UserName, e.Password, e.Question, e.Password); _mailService.SendMail("Twoje konto w systemie SOPS zostało utworzone", message, e.Email); return(Json(true)); } switch (status) { case EmployeeCreateStatus.DuplicateMail: ModelState.AddModelError("DuplicateMail", "Użytkownik o podanym adresie email już istnieje"); break; case EmployeeCreateStatus.UserAlreadyExist: ModelState.AddModelError("UserAlreadyExist", "Użytkownik już istnieje"); break; case EmployeeCreateStatus.InvalidAnswer: ModelState.AddModelError("InvalidAnswer", "Niepoprawna odpowiedź"); break; case EmployeeCreateStatus.UserRejected: ModelState.AddModelError("UserRejected", "Użytkownik odrzucony"); break; case EmployeeCreateStatus.ProviderError: ModelState.AddModelError("ProviderError", "Wystąpił nieoczekiwany bląd"); break; case EmployeeCreateStatus.InvalidUserName: ModelState.AddModelError("InvalidUserName", "Niepoprawna nazwa użytkownika"); break; case EmployeeCreateStatus.InvalidQuestion: ModelState.AddModelError("InvalidQuestion", "Niepoprawne pytanie"); break; case EmployeeCreateStatus.InvalidPassword: ModelState.AddModelError("InvalidPassword", "Niepoprawna hasło"); break; case EmployeeCreateStatus.InvalidEmail: ModelState.AddModelError("InvalidEmail", "Niepoprawny adres email"); break; } } return(PartialView("Partials/_FormSubmitResult", ModelState)); }