public string Handle(CreateStudentCommand request) { try { var student = new Student(request.FirstName, request.LastName, request.BirthDate, request.Gpi); _context.Student.Add(student); _context.SaveChanges(); var studentDetails = new StudentDetailsDto(student.Id, student.FirstName, student.LastName, student.BirthDate, student.Gpi); _context.StudentDetails.Add(studentDetails); _context.SaveChangesAsync(); return("succeded"); } catch (DbEntityValidationException exception) { return(exception.GetValidations()); } catch (Exception exception) { return(exception.Message); } }
public Task <CommandExecutionResult <Student> > Handle(CreateStudentCommand request) { try { var student = new Student(request.FirstName, request.LastName, request.BirthDate, request.Gpi); _context.Set <Student>().Add(student); _context.SaveChangesAsync(); return(Task.FromResult(new CommandExecutionResult <Student>() { Success = true, Data = student })); } catch (Exception exception) { return(Task.FromResult(new CommandExecutionResult <Student>() { Success = false, Exception = exception })); } }