public async Task <Unit> Handle(DeleteCustomer request, CancellationToken cancellationToken) { var entity = _context.Destinations.SingleOrDefault(x => x.Id == request.Id); if (entity == null) { throw new CustomerNotFoundException(); } _context.Destinations.Remove(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <CustomerPreviewDto> Handle(CreateCustomer request, CancellationToken cancellationToken) { var entity = new Customer { Id = request.Id, Email = request.Email, Firstname = request.Firstname, Surname = request.Surname, Password = request.Password, CreatedBy = request.CreatedBy, CreatedOn = request.CreatedOn }; _context.Customers.Add(entity); await _context.SaveChangesAsync(cancellationToken); return(await _mediator.Send(new GetCustomerPreviewQuery { Id = entity.Id })); }
public async Task <Unit> Handle(UpdateDestination request, CancellationToken cancellationToken) { var id = int.Parse(request.Id); var entity = _context.Destinations.SingleOrDefault(x => x.Id == id); if (entity == null) { throw new DestinationNotFoundException(); } entity.Name = request.Name; entity.Description = request.Description; entity.ModifiedBy = request.ModifiedBy; entity.ModifiedOn = request.ModifiedOn; _context.Destinations.Update(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <DestinationPreviewDto> Handle(CreateDestination request, CancellationToken cancellationToken) { int id = int.Parse(request.Id); var entity = new Destination { Id = id, Description = request.Description, Name = request.Name, CreatedBy = request.CreatedBy, CreatedOn = request.CreatedOn }; _context.Destinations.Add(entity); await _context.SaveChangesAsync(cancellationToken); return(await _mediator.Send(new GetDestinationPreviewQuery() { Id = entity.Id })); }
public async Task <Unit> Handle(UpdateCustomer request, CancellationToken cancellationToken) { var entity = _context.Customers.SingleOrDefault(x => x.Id == request.Id); if (entity == null) { throw new CustomerNotFoundException(); } entity.Firstname = request.Firstname; entity.Email = request.Email; entity.ModifiedOn = request.ModifiedOn; entity.ModifiedBy = request.ModifiedBy; entity.Password = request.Password; entity.Surname = request.Surname; _context.Customers.Update(entity); await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }