コード例 #1
0
        public async Task<BaseUpdateModel<KernelProductionDto>> Save(KernelProductionDto dto)
        {
            var entity = dto.Id.IsNullOrEmpty() ? new KernelProduction() : await Session.LoadAsync<KernelProduction>(dto.Id);

            SetUpdateText(dto);

            Mapper.Map(dto, entity);
            UpdateAuditInfo(entity);

            var lot = await Session.LoadAsync<Lot>(dto.LotId);
            if(lot==null)
                throw new NotFoundException($"Lote {dto.LotId.ToLotNumber()} não existe");

            entity.Product = await Session.LoadAsync<Product>(dto.ProductId);

            if (entity.Product==null)
                throw new NotFoundException($"Produto com Id {dto.ProductId.FromRavenId()} não existe");

            await Session.StoreAsync(entity);
            await Session.SaveChangesAsync();

            dto.Id = entity.Id;

            return new BaseUpdateModel<KernelProductionDto>(dto, $"{UpdateText} produção de {(await Session.LoadAsync<Product>(dto.ProductId)).Name}",true);
        }
コード例 #2
0
        public async Task<KernelProductionDto> GetById(string id)
        {
            if (id.IsNullOrEmpty())
                throw new ArgumentNullException(nameof(id));

            var entity = await Session.LoadAsync<KernelProduction>(id);

            if(entity==null)
                throw new NotFoundException($"O produção de amendoas com Id {id.FromRavenId()} não existe");

            var dto = new KernelProductionDto
            {
                Id = entity.Id,
                ProductId = entity.Product.Id,
                LotId = entity.LotId,
                Date = entity.Date,
                QuantityKg = entity.QuantityKg
            };

            return dto;
        }