public async Task AddAttributeUnitAsync(AttributeUnitDto unit, CancellationToken cancellationToken = default(CancellationToken)) { var a = new AttributeUnit { Name = unit.Name, }; try { _dbContext.Add(a); await _dbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateException ex) { throw new InvalidItemException(a, ex); } }
public async Task UpdateAttributeUnitAsync(int unitId, AttributeUnitDto unit, CancellationToken cancellationToken = default(CancellationToken)) { var b = new AttributeUnit { Id = unitId, Name = unit.Name }; _dbContext.Attach(b).State = EntityState.Modified; try { await _dbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException ex) { throw new ItemNotFoundException(unitId, "Attribute unit", ex); } catch (DbUpdateException ex) { throw new InvalidItemException(b, ex); } }
public Task Put(int attributeUnitId, [FromBody] AttributeUnitDto attributeUnit) { return(_attributesService.UpdateAttributeUnitAsync(attributeUnitId, attributeUnit, HttpContext.RequestAborted)); }
public Task Post([FromBody] AttributeUnitDto attributeUnit) { return(_attributesService.AddAttributeUnitAsync(attributeUnit, HttpContext.RequestAborted)); }