public string RegisterStudent(string firstName, string lastName, long nameSuffixId, string email, long favoriteCourseId) { Course course = Course.FromId(favoriteCourseId); if (course == null) { return("Course not found"); } Result <Email> emailResult = Email.Create(email); if (emailResult.IsFailure) { return(emailResult.Error); } Suffix suffix = Suffix.FromId(nameSuffixId); Result <Name> nameResult = Name.Create(firstName, lastName, suffix); if (nameResult.IsFailure) { return(nameResult.Error); } var student = new Student(nameResult.Value, emailResult.Value, course); _contex.Attach(student); _contex.SaveChanges(); return("OK"); }
public string EditPersonalInfo(long studentId, string firstName, string lastName, long nameSuffixId, string email, long favoriteCourseId) { Course course = Course.FromId(favoriteCourseId); if (course == null) { return("Course not found"); } var student = _studentRepo.GetById(studentId); Result <Email> emailResult = Email.Create(email); if (emailResult.IsFailure) { return(emailResult.Error); } Suffix suffix = Suffix.FromId(nameSuffixId); Result <Name> nameResult = Name.Create(firstName, lastName, suffix); if (nameResult.IsFailure) { return(nameResult.Error); } student.EditPersonalInfo(nameResult.Value, emailResult.Value, course); _contex.SaveChanges(); return("OK"); }