public async Task DeleteAttributeAsync(int attributeId, CancellationToken cancellationToken = default(CancellationToken)) { var attribute = new Domain.Core.Attribute { Id = attributeId }; _dbContext.Attach(attribute).State = EntityState.Deleted; try { await _dbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException ex) { throw new ItemNotFoundException(attributeId, "Attribute", ex); } }
public async Task AddAttributeAsync(AttributeDto attribute, CancellationToken cancellationToken = default(CancellationToken)) { var a = new Domain.Core.Attribute { Name = attribute.Name, UnitId = attribute.UnitId }; try { _dbContext.Add(a); await _dbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateException ex) { throw new InvalidItemException(a, ex); } }
public async Task UpdateAttributeAsync(int attributeId, AttributeDto attribute, CancellationToken cancellationToken = default(CancellationToken)) { var b = new Domain.Core.Attribute { Id = attributeId, Name = attribute.Name, UnitId = attribute.UnitId }; _dbContext.Attach(b).State = EntityState.Modified; try { await _dbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException ex) { throw new ItemNotFoundException(attributeId, "Attribute unit", ex); } catch (DbUpdateException ex) { throw new InvalidItemException(b, ex); } }