public async Task <ProductVarietyDto> SaveAsync(Guid orgId, ProductVarietyDto dto) { if (orgId == null || orgId == Guid.Empty) { throw new ArgumentNullException("orgId", "Org id is missing"); } ProductVariety variety = _mapper.Map <ProductVariety>(dto); if (variety.Id == Guid.Empty) { variety.OrgId = orgId; variety.DateCreated = DateTime.UtcNow; variety.DateModified = null; await _context.ProductVarieties.AddAsync(variety); } else { variety.DateModified = DateTime.UtcNow; _context.ProductVarieties.Update(variety); } await _context.SaveChangesAsync(); dto = _mapper.Map <ProductVarietyDto>(variety); return(dto); }
public async Task <bool> DeleteAsync(Guid varietyId) { ProductVariety variety = await _context.ProductVarieties .FindAsync(varietyId); if (variety != null) { _context.ProductVarieties.Remove(variety); await _context.SaveChangesAsync(); return(true); } throw new KeyNotFoundException("Product variety not found"); }