public ActionResult Create(Student student) { if (Request.IsAjaxRequest()) { string answer = "Введені дані містять помилку."; bool success = false; //string property = null; //string propertyMessage = null; if (ModelState.IsValid) { service.Add(student); //RedirectToAction("Index"); answer = "Внесення студента успішно завершено."; success = true; } //if (!success) //{ // property = "Birthday"; // propertyMessage = ModelState["Birthday"].Errors.FirstOrDefault().ErrorMessage; //} //BaseService.Dictionaries.FillAllDictionaries(student); return Json(new { Id = student.Id, Answer = answer, Success = success }); //Property = property, PropertyMessage = propertyMessage }); } if (ModelState.IsValid) { service.Add(student); return RedirectToAction("Index"); } //BaseService.Dictionaries.FillAllDictionaries(student); return View(student); }
static Student[] TestCreateStudent(Group group, int studentID) { var result = new Student[10]; result[0] = new Student("Ivanov", "Ivan", "I.", Sex.Male, group, studentID++, "01.01.1960"); result[1] = new Student("Ivanov", "Cyril", "I.", Sex.Male, group, studentID++, "01.01.1960"); result[2] = new Student("Petrov", "Ivan", "I.", Sex.Male, group, studentID++, "02.01.1960"); result[3] = new Student("Sidorov", "Ivan", "I.", Sex.Male, group, studentID++, "03.01.1960"); result[4] = new Student("Ivanov", "Oleg", "I.", Sex.Male, group, studentID++, "04.01.1960"); result[5] = new Student("Ivanov", "Anna", "I.", Sex.Female, group, studentID++, "06.01.1960"); result[6] = new Student("Ivanov", "Ivan", "V.", Sex.Male, group, studentID++, "07.01.1960"); result[7] = new Student("Kozlov", "Ivan", "I.", Sex.Male, group, studentID++, "10.01.1960"); result[8] = new Student("Ivanov", "Arman", "I.", Sex.Male, group, studentID++, "12.01.1960"); result[9] = new Student("Bugaev", "Ivan", "K.", Sex.Male, group, studentID, "20.01.1960"); return result; }
public static XElement XMLElementStudent(Student student) { if (student == null) throw new ArgumentNullException("student"); var attribLeader = new XAttribute("leader", student.Group.Leader == student ? "true" : "false"); var element = new XElement("student", attribLeader); element.Add(new XElement("firstName", student.FirstName)); element.Add(new XElement("middleName", student.MiddleName)); element.Add(new XElement("lastName", student.LastName)); element.Add(new XElement("sex", student.Sex)); element.Add(new XElement("dateOfBirth", student.DateOfBirth.Date)); element.Add(new XElement("id", student.StudentID)); element.Add(new XElement("groupNumber", student.Group.GroupNumber)); return element; }
public static void SaveStudentToXML(string path, Student student) { if (string.IsNullOrWhiteSpace(path)) return; path += student.LastName + '_' + student.FirstName + '_' + student.StudentID + ".xml"; using (var stream = new FileStream(path, FileMode.Create)) { SaveStudentToXML(stream, student); } }
public static void SaveStudentToXML(FileStream stream, Student student) { if (stream == null) throw new ArgumentNullException("stream"); if (student == null) throw new ArgumentNullException("student"); var document = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), XMLElementStudent(student)); document.Save(stream); }
public static Student LoadStudentFromXML(FileStream stream, Group group) { try { var reader = new XmlTextReader(stream); var firstName = string.Empty; var middleName = string.Empty; var lastName = string.Empty; Sex sex = Sex.Male; var dateOfBirth = string.Empty; var studentID = string.Empty; var leader = false; while (reader.Read()) { switch (reader.Name) { case "student": if (reader.AttributeCount >= 1) leader = bool.Parse(reader.GetAttribute("leader")); break; case "firstName": firstName = reader.ReadString(); break; case "middleName": middleName = reader.ReadString(); break; case "lastName": lastName = reader.ReadString(); break; case "sex": Enum.TryParse(reader.ReadString(), out sex); break; case "dateOfBirth": dateOfBirth = reader.ReadString(); break; case "id": studentID = reader.ReadString(); break; } } var student = new Student(lastName, firstName, middleName, sex, group, int.Parse(studentID), dateOfBirth); if (group != null) { group.Add(student); if (leader) group.SetLeader(student); } return student; } catch (ArgumentNullException exception) { throw new ArgumentNullException(exception.Source); } catch (XmlException exception) { throw new XmlException(exception.Source); } catch (InvalidOperationException exception) { throw new InvalidOperationException(exception.Source); } }
public ActionResult Edit(Student student) { if (ModelState.IsValid) { service.Edit(student); return RedirectToAction("Index"); } //BaseService.Dictionaries.FillAllDictionaries(student); return View(student); }