public ActionResult CreateStudent() { var model = new UserCommonViewModel() { StudentMeta = new StudentViewModel(), IsNewUser = true }; return View("Create", model); }
public ActionResult CreatePrepod() { ViewBag.Dapartments = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Кафедры).ToList(), "Id", "Name"); ViewBag.Degree = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.УченаяСтепень).ToList(), "Id", "Name"); var model = new UserCommonViewModel() { PrepodMeta = new PrepodViewModel() { DepartmentsIds = new List<int>() }, IsNewUser = true }; return View("Create", model); }
public ActionResult HomeUserPage(bool? isPartial, int? userId) { var id = userId.HasValue ? userId.Value : CurrentUserId; var user = _accountService.GetUser(id); if (user == null) { return View("Login"); } else { UserCommonViewModel model; var userMeta = user.UserMeta.FirstOrDefault(); var studentStudentMeta = user.Student_StudentMeta.FirstOrDefault(); string numberTasks = user.UserTask.Aggregate("", (current, task) => current + (task.TaskId + ";")); if (studentStudentMeta != null) { model = new UserCommonViewModel() { //IsNewUser = false, StudentMeta = new StudentViewModel() { AdmissionDate = studentStudentMeta.AdmissionDate.Year, FacultyId = studentStudentMeta.FacultyId, FlowId = studentStudentMeta.FlowId, GraduationDate = studentStudentMeta.GraduationDate.Year, MarkBookNumber = studentStudentMeta.MarkBookNumber, GroupId = studentStudentMeta.GroupId, IsDismissed = studentStudentMeta.IsDismissed, SpecialityId = studentStudentMeta.SpecialtyId, StudentCardNumber = studentStudentMeta.StudentCardNumber, IdSpecialtyMeta = studentStudentMeta.IdSpecialtyMeta }, Login = user.Login, //Password = user.Password, FirstName = userMeta.FirstName, LastName = userMeta.LastName, MiddleName = userMeta.MiddleName, IsBlocked = user.BlockDate != null, Phone = userMeta.Contact.PhoneNumber, AdditionalPhone = userMeta.Contact.AdditionalPhoneNumber, Email = userMeta.Contact.Email, Skype = userMeta.Contact.Skype, Tasks = numberTasks }; ViewBag.FacultyName = GetItemsOfDictionary(DictionaryTypeEnum.Факультеты) .Find(p => p.Id == studentStudentMeta.FacultyId) .Name; Spezialnost_SpezialnostMeta meta = _adminData.GetSpezMetaInfo(studentStudentMeta.IdSpecialtyMeta); ViewBag.StartYear = meta.GodPostup; ViewBag.FinishYear = (meta.GodPostup + meta.SrokObuch).ToString(); } else { var prepodPrepodMeta = user.Prepod_PrepodMeta.FirstOrDefault(); var prepodMeta = new PrepodViewModel() { }; if (prepodPrepodMeta != null) { prepodMeta = new PrepodViewModel() { DegreeId = prepodPrepodMeta.DegreeId }; } model = new UserCommonViewModel() { IsNewUser = false, PrepodMeta = prepodMeta, Login = user.Login, //Password = user.Password, FirstName = userMeta.FirstName, LastName = userMeta.LastName, MiddleName = userMeta.MiddleName, IsBlocked = user.BlockDate != null, Phone = userMeta.Contact.PhoneNumber, AdditionalPhone = userMeta.Contact.AdditionalPhoneNumber, Email = userMeta.Contact.Email, Skype = userMeta.Contact.Skype, Tasks = numberTasks }; } model.IsPartialView = (isPartial.HasValue && isPartial.Value); return View(model); } }
public ActionResult Edit(int id) { CacheService.Remove("UserData" + id + "|"); var user = GetUserById(id); UserCommonViewModel model; var userMeta = user.UserMeta.FirstOrDefault(); var studentStudentMeta = user.Student_StudentMeta.FirstOrDefault(); string numberTasks = user.UserTask.Aggregate("", (current, task) => current + (task.TaskId + ";")); if (studentStudentMeta != null) { model = new UserCommonViewModel() { //IsNewUser = false, StudentMeta = new StudentViewModel() { AdmissionDate = studentStudentMeta.AdmissionDate.Year, FacultyId = studentStudentMeta.FacultyId, FlowId = studentStudentMeta.FlowId, GraduationDate = studentStudentMeta.GraduationDate.Year, MarkBookNumber = studentStudentMeta.MarkBookNumber, GroupId = studentStudentMeta.GroupId, IsDismissed = studentStudentMeta.IsDismissed, SpecialityId = studentStudentMeta.SpecialtyId, StudentCardNumber = studentStudentMeta.StudentCardNumber, IdSpecialtyMeta = studentStudentMeta.IdSpecialtyMeta }, Login = user.Login, //Password = user.Password, FirstName = userMeta.FirstName, LastName = userMeta.LastName, MiddleName = userMeta.MiddleName, IsBlocked = user.BlockDate != null, Phone = userMeta.Contact.PhoneNumber, AdditionalPhone = userMeta.Contact.AdditionalPhoneNumber, Email = userMeta.Contact.Email, Skype = userMeta.Contact.Skype, Tasks = numberTasks }; } else { var prepodMeta = new PrepodViewModel() { }; var prepodPrepodMeta = user.Prepod_PrepodMeta.FirstOrDefault(); if (prepodPrepodMeta != null) { prepodMeta = new PrepodViewModel() { DegreeId = prepodPrepodMeta.DegreeId, DepartmentsIds = prepodPrepodMeta.Prepod_PrepodiCafedri.Select(dep => dep.IdCafedri).ToList(), DepartmentsIdsString = prepodPrepodMeta.Prepod_PrepodiCafedri.Aggregate("", (current, depID) => current + (depID.IdCafedri + ";")) }; } model = new UserCommonViewModel() { IsNewUser = false, PrepodMeta = prepodMeta, Login = user.Login, //Password = user.Password, FirstName = userMeta.FirstName, LastName = userMeta.LastName, MiddleName = userMeta.MiddleName, IsBlocked = user.BlockDate != null, Phone = userMeta.Contact.PhoneNumber, AdditionalPhone = userMeta.Contact.AdditionalPhoneNumber, Email = userMeta.Contact.Email, Skype = userMeta.Contact.Skype, Tasks = numberTasks }; if (!String.IsNullOrEmpty(prepodMeta.DepartmentsIdsString)) { List<SelectList> departmentsList = new List<SelectList>(); foreach (var depId in prepodMeta.DepartmentsIdsString.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { departmentsList.Add(new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Кафедры).ToList(), "Id", "Name", depId)); } ViewBag.Dapartments = departmentsList; } else ViewBag.Dapartments = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Кафедры).ToList(), "Id", "Name"); } ViewBag.Degree = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.УченаяСтепень).ToList(), "Id", "Name"); ViewBag.Facultaty = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Факультеты).ToList(), "Id", "Name"); ViewBag.Speciality = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Специальности).ToList(), "Id", "Name"); ViewBag.Years = new SelectList(Enumerable.Range((DateTime.Now.Year - 6), 15)); ViewBag.Number = new SelectList(Enumerable.Range(1, 8)); ViewBag.Groups = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Группы).ToList(), "Id", "Name"); ViewBag.Flows = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Потоки).ToList(), "Id", "Name"); return View("Create", model); }
public ActionResult Save(UserCommonViewModel userModel) { var newUser = new User(); if (userModel.IsNewUser != true) { CacheService.Remove("UserData" + userModel.Login + "|"); newUser = GetUserByLogin(userModel.Login); } var isNew = userModel.IsNewUser; try { if (!isNew && String.IsNullOrEmpty(userModel.Password)) { if (ModelState["Password"].Errors.Count > 0) ModelState["Password"].Errors.RemoveAt(0); } // При создании пользователя надо проигнорить поле Id } catch (Exception ex) { #region Логирование //LogHelper.AddSystemLogMessage(new SystemLogMessage() //{ // AuditEventId = AuditEvents.СистемнаяОшибка, // UserId = CurrentUserId, // EventTypeId = EventTypes.Ошибка, // IPAddress = Request.UserHostAddress, // ComputerName = NetworkHelper.GetHostNameByHostAddress(Request.UserHostAddress), // Date = DateTime.Now, // Detalization = String.Format("Произошла ошибка при правке модели пользователя: {0}", ex.Message + "\r\n" + ex.InnerException + "\r\n" + ex.StackTrace) //}); #endregion } #region Validity if (ModelState.IsValid) { newUser.Login = userModel.Login; if (!String.IsNullOrEmpty(userModel.Password)) newUser.Password = PasswordHelper.Sha1EncryptPassword(userModel.Password); newUser.IsDeleted = false; newUser.BlockReason = String.Empty; UserMeta userMeta = newUser.UserMeta.FirstOrDefault(); if (userMeta != null) { userMeta.LastName = userModel.LastName; userMeta.FirstName = userModel.FirstName; userMeta.MiddleName = userModel.MiddleName; if (userMeta.Contact != null) { userMeta.Contact.Email = userModel.Email; userMeta.Contact.Skype = userModel.Skype; userMeta.Contact.PhoneNumber = userModel.Phone; userMeta.Contact.AdditionalPhoneNumber = userModel.AdditionalPhone; } } else { newUser.UserMeta.Add(new UserMeta { LastName = userModel.LastName, FirstName = userModel.FirstName, MiddleName = userModel.MiddleName, Contact = new Contact { Email = userModel.Email, Skype = userModel.Skype, PhoneNumber = userModel.Phone, AdditionalPhoneNumber = userModel.AdditionalPhone } }); } if (userModel.StudentMeta != null) { var studentMeta = newUser.Student_StudentMeta.FirstOrDefault(); Spezialnost_SpezialnostMeta meta = _adminData.GetSpezMetaInfo(userModel.StudentMeta.IdSpecialtyMeta); if (studentMeta != null) { studentMeta.FacultyId = userModel.StudentMeta.FacultyId; studentMeta.SpecialtyId = userModel.StudentMeta.SpecialityId; studentMeta.AdmissionDate = new DateTime(meta.GodPostup, 1, 1); studentMeta.GraduationDate = new DateTime(meta.GodPostup + meta.SrokObuch, 1, 1); studentMeta.FlowId = userModel.StudentMeta.FlowId; studentMeta.GroupId = userModel.StudentMeta.GroupId; studentMeta.StudentCardNumber = userModel.StudentMeta.StudentCardNumber; studentMeta.MarkBookNumber = userModel.StudentMeta.MarkBookNumber; studentMeta.IsDismissed = false; studentMeta.IdSpecialtyMeta = userModel.StudentMeta.IdSpecialtyMeta; studentMeta.FormOfStuduId = meta.IdFrmObuch; } else { newUser.Student_StudentMeta.Add(new Student_StudentMeta() { FacultyId = userModel.StudentMeta.FacultyId, SpecialtyId = userModel.StudentMeta.SpecialityId, AdmissionDate = new DateTime(meta.GodPostup, 1, 1), GraduationDate = new DateTime(meta.GodPostup + meta.SrokObuch, 1, 1), FlowId = userModel.StudentMeta.FlowId, GroupId = userModel.StudentMeta.GroupId, StudentCardNumber = userModel.StudentMeta.StudentCardNumber, MarkBookNumber = userModel.StudentMeta.MarkBookNumber, IsDismissed = false, IdSpecialtyMeta = userModel.StudentMeta.IdSpecialtyMeta, FormOfStuduId = meta.IdFrmObuch }); } } if (userModel.PrepodMeta != null) { if (userModel.IsNewUser) { Prepod_PrepodMeta prepod_meta = new Prepod_PrepodMeta(); var departments = userModel.PrepodMeta.DepartmentsIdsString; if (!String.IsNullOrEmpty(departments)) { foreach (var depId in departments.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { prepod_meta.Prepod_PrepodiCafedri.Add(new Prepod_PrepodiCafedri() { IdCafedri = Convert.ToInt32(depId), IdSotr = userModel.Id, Stavka = 1, TipZanyatosti = 79 }); } } prepod_meta.DegreeId = userModel.PrepodMeta.DegreeId; prepod_meta.IsDismissed = false; newUser.Prepod_PrepodMeta.Add(prepod_meta); } else { //В КОДЕ УСТАНОВЛЕНО МИНИМУМ ОДНА КАФЕДРА List<Prepod_PrepodiCafedri> cafedry = new List<Prepod_PrepodiCafedri>(); var departments = userModel.PrepodMeta.DepartmentsIdsString; if (!String.IsNullOrEmpty(departments)) { foreach (var depId in departments.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { cafedry.Add(new Prepod_PrepodiCafedri() { IdCafedri = Convert.ToInt32(depId), IdSotr = newUser.Prepod_PrepodMeta.First().Id, Stavka = 1, TipZanyatosti = 79 }); } UpdateCafedry(cafedry); newUser.Prepod_PrepodMeta.First().DegreeId = userModel.PrepodMeta.DegreeId; newUser.Prepod_PrepodMeta.First().IsDismissed = false; } else { newUser.Prepod_PrepodMeta.Add(new Prepod_PrepodMeta() { DegreeId = userModel.PrepodMeta.DegreeId, IsDismissed = false }); } } } bool result; if (isNew) AddUser(newUser); else { UpdateUser(newUser); } var firstResult = DB_SaveChanges(); if (firstResult) { var editresult = AddingRolesAndTasks(newUser.Login, userModel.Tasks); result = editresult; } else { result = false; } if (result) { if (isNew) return Json(new { isValid = true, type = "success", message = "Пользователь " + userModel.Login + " добавлен успешно!" }); else { return Json(new { isValid = true, type = "success", message = "Пользователь " + userModel.Login + " редактирован успешно!" }); } } else { if (isNew) return Json( new { isValid = true, type = "error", message = "Пользователь " + userModel.Login + " не добавлен. Ошибка при сохранении данных!" }); else { return Json(new { isValid = true, type = "success", message = "Не удалось сохранить изменения для пользователя " + userModel.Login + " !" }); } } } #endregion //Добавила (валидация видимая) if (userModel.PrepodMeta != null) { List<SelectList> departmentsList = new List<SelectList>(); userModel.PrepodMeta.DepartmentsIds = new List<int>(); foreach (var depId in userModel.PrepodMeta.DepartmentsIdsString.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { userModel.PrepodMeta.DepartmentsIds.Add(Convert.ToInt16(depId)); departmentsList.Add(new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.Кафедры).ToList(), "Id", "Name", depId)); } ViewBag.Dapartments = departmentsList; ViewBag.Degree = new SelectList(GetItemsOfDictionary(DictionaryTypeEnum.УченаяСтепень).ToList(), "Id", "Name"); } return Json(new { view = RenderView.RenderViewToString(ControllerContext, "Create", userModel), isValid = false, type = "error", message = "Проверьте введенные данные!" }); }