Exemplo n.º 1
0
        public async Task Update(SaleReturn saleReturn)
        {
            try
            {
                AppDbContext            _db               = new AppDbContext();
                ValidationContext       context           = new ValidationContext(saleReturn, null, null);
                List <ValidationResult> validationResults = new List <ValidationResult>();
                bool isValid = Validator.TryValidateObject(saleReturn, context, validationResults);

                if (!isValid)
                {
                    throw new InvaliedValuesException(validationResults.First().ErrorMessage);
                }
                await Task.Run(() => _db.SaleReturns.Update(saleReturn));

                await _db.SaveChangesAsync();
            }
            catch (InvaliedValuesException e)
            {
                throw e;
            }
            catch (Exception)
            {
                throw new DatabaseException("Failed to Update Sale Return Record.");
            }
        }
Exemplo n.º 2
0
        public async Task Remove(SaleReturn saleReturn)
        {
            try
            {
                AppDbContext _db = new AppDbContext();
                await Task.Run(() => _db.SaleReturns.Remove(saleReturn));

                await _db.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw new DatabaseException("Failed to Delete Sale Return Record.");
            }
        }