public async Task <Guid> Handle(CreateCatalogCommand request, CancellationToken cancellationToken) { var entity = _mapper.Map <CreateCatalogCommand, Catalog>(request); await _context.Catalogs.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public async Task<Guid> Handle(UpdateFieldCommand request, CancellationToken cancellationToken) { var entity = await _context.Fields.FindAsync(request.Id); if (entity == null) throw new NotFoundException(nameof(Field), request.Id); var mappedEntity = _mapper.Map<UpdateFieldCommand, Field>(request); mappedEntity.CatalogId = entity.CatalogId; _context.UpdateEntity(entity, mappedEntity); await _context.SaveChangesAsync(cancellationToken); return entity.Id; }
public async Task <Guid> Handle(UpdateCatalogCommand request, CancellationToken cancellationToken) { var entity = await _context.Catalogs.FindAsync(request.Id); if (entity == null) { throw new NotFoundException(nameof(Catalog), request.Id); } var mappedEntity = _mapper.Map <UpdateCatalogCommand, Catalog>(request); _context.UpdateEntity(entity, mappedEntity); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public async Task <Guid> Handle(AddFieldValueCommand request, CancellationToken cancellationToken) { var entity = await _context.Fields.FindAsync(request.FieldId); if (entity == null) { throw new NotFoundException(nameof(Field), request.FieldId); } var mappedFieldValue = _mapper.Map <AddFieldValueCommand, FieldValue>(request); mappedFieldValue.Date = DateTime.Now; entity.FieldValues.Add(mappedFieldValue); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public async Task <Guid> Handle(CreateFieldCommand request, CancellationToken cancellationToken) { var entity = _mapper.Map <CreateFieldCommand, Field>(request); if (await _context.Catalogs.AnyAsync(x => x.Id != entity.CatalogId, cancellationToken)) { throw new NotFoundException(nameof(Catalog), entity.CatalogId); } if (await _context.Types.AnyAsync(x => x.Id != entity.TypeId, cancellationToken)) { throw new NotFoundException(nameof(Type), entity.TypeId); } await _context.Fields.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }