public async Task <Unit> Handle(DeleteUserCommand request, CancellationToken cancellationToken) { var entity = await context.Users.FindAsync(request.Id); if (entity == null) { throw new NotFoundException(nameof(Domain.Entities.User), request.Id); } context.Users.Remove(entity); await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <int> Handle(CreateUserCommand request, CancellationToken cancellationToken) { //var entity = new Domain.Entities.User() //{ // Id = request.Id, // Name = request.Name, // Address = request.Address, // Age = request.Age, // salary = request.salary, // Postion = request.Postion, // JoiningDate = DateTime.Parse(request.JoiningDate), // Phone = request.Phone, //}; var entity = mapper.Map <Domain.Entities.User> (request); context.Users.Add(entity); await context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public async Task <Unit> Handle(UpdateUserCommand request, CancellationToken cancellationToken) { var entity = await context.Users.SingleOrDefaultAsync(a => a.Id == request.Id, cancellationToken); if (entity == null) { throw new NotFoundException(nameof(Domain.Entities.User), request.Id); } entity.Address = request.Address; entity.Name = request.Name; entity.Age = request.Age; entity.JoiningDate = DateTime.Parse(request.JoiningDate); entity.Phone = request.Phone; entity.Postion = request.Postion; entity.salary = request.salary; context.Users.Update(entity); await context.SaveChangesAsync(cancellationToken); return(Unit.Value); }