public IDoctor Create(string firstName, string lastName) { var instance = new Doctor { FirstName = firstName, LastName = lastName }; Add(instance); SaveChanges(); Entry(instance).GetDatabaseValues(); return instance; /* todo this code should be an aspect (AOP) try { .... } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } */ }
private static IDoctor ToDoctor(IDoctorForResponse doctor) { string firstName = DefaultText(doctor.FirstName, "FirstName"); string lastName = DefaultText(doctor.LastName, "LastName"); IDoctor instance = new Doctor { Id = doctor.Id, FirstName = firstName, LastName = lastName }; return instance; }