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(UpdateStudentCommand request) { try { var student = _context.Set <Student>().Find(request.Id); var updated = new Student(request.FirstName, request.LastName, request.BirthDate); _context.SaveChanges(); return(Task.FromResult(new CommandExecutionResult <Student>() { Success = true, Data = student })); } catch (Exception exception) { return(Task.FromResult(new CommandExecutionResult <Student>() { Success = false, Exception = exception })); } }
public string AddFriend(Friend friend) { try { _context.Friend.Add(friend); _context.SaveChanges(); return("succeded"); } catch (DbEntityValidationException exception) { return(GetValidations(exception)); } catch (Exception exception) { return(exception.Message); } }