Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public async Task <ProductVarietyDto> GetByIdAsync(Guid varietyId)
        {
            ProductVarietyDto variety = await _context.ProductVarieties
                                        .ProjectTo <ProductVarietyDto>(_mapper.ConfigurationProvider)
                                        .AsNoTracking()
                                        .SingleOrDefaultAsync(pc => pc.Id == varietyId);

            if (variety != null)
            {
                return(variety);
            }

            throw new KeyNotFoundException("Product variety not found");
        }