public JsonResult UpdatePerconalData(PersonalDataViewModel model, string avatar) { if (Roles.IsUserInRole("lector")) { var modData = new ModifyLecturerViewModel(new Lecturer { FirstName = model.Name, LastName = model.Surname, MiddleName = model.Patronymic, IsLecturerHasGraduateStudents = model.IsLecturerHasGraduateStudents, IsSecretary = model.IsSecretary, Skill = model.Skill, User = new User { UserName = model.UserName, Avatar = avatar, About = model.About, SkypeContact = model.SkypeContact, Phone = model.Phone, Email = model.Email, Id = WebSecurity.CurrentUserId }, Id = WebSecurity.CurrentUserId }); modData.ModifyLecturer(); } else { var modData = new ModifyStudentViewModel(new Student { FirstName = model.Name, LastName = model.Surname, MiddleName = model.Patronymic, User = new User { UserName = model.UserName, Avatar = avatar, About = model.About, SkypeContact = model.SkypeContact, Phone = model.Phone, Email = model.Email, Id = WebSecurity.CurrentUserId }, Id = WebSecurity.CurrentUserId }); modData.ModifyStudent(); } return(Json(true)); }
public ActionResult EditStudent(ModifyStudentViewModel model, int id) { if (ModelState.IsValid) { try { model.ModifyStudent(); ViewBag.ResultSuccess = true; } catch { ModelState.AddModelError(string.Empty, string.Empty); } } return(null); }
public IActionResult SaveStudent(ModifyStudentViewModel model) { try { var user = UsersManagementService.GetUser(model.Id); if (user != null) { model.ModifyStudent(); return(Ok()); } return(BadRequest()); } catch (Exception ex) { return(ServerError500(ex.Message)); } }
public ActionResult EditStudentAjax(ModifyStudentViewModel model) { if (ModelState.IsValid) { try { var user = UsersManagementService.GetUserByName(model.Name, model.Surname, model.Patronymic); if (user == null || user.Id == model.Id) { model.ModifyStudent(); return(Json(new { resultMessage = "Студент сохранен" })); } ModelState.AddModelError(string.Empty, "Пользователь с таким именем уже существует"); } catch { ModelState.AddModelError(string.Empty, string.Empty); } } return(PartialView("_EditStudentView", model)); }