Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 public Task Put(int attributeUnitId, [FromBody] AttributeUnitDto attributeUnit)
 {
     return(_attributesService.UpdateAttributeUnitAsync(attributeUnitId, attributeUnit, HttpContext.RequestAborted));
 }
Ejemplo n.º 4
0
 public Task Post([FromBody] AttributeUnitDto attributeUnit)
 {
     return(_attributesService.AddAttributeUnitAsync(attributeUnit, HttpContext.RequestAborted));
 }