public FpReturnFromBuyerViewModel MapToViewModel(FpReturnFromBuyerModel model)
 {
     return(new FpReturnFromBuyerViewModel()
     {
         Active = model.Active,
         Buyer = new BuyerViewModel()
         {
             Code = model.BuyerCode,
             Id = model.BuyerId,
             Name = model.BuyerName
         },
         Code = model.Code,
         CodeProduct = model.CodeProduct,
         CoverLetter = model.CoverLetter,
         Date = model.Date,
         Destination = model.Destination,
         Details = MapDetailToViewModel(model.Details),
         Id = model.Id,
         SpkNo = model.SpkNo,
         Storage = new StorageIntegrationViewModel()
         {
             code = model.StorageCode,
             name = model.StorageName,
             _id = model.StorageId
         },
         _CreatedAgent = model._CreatedAgent,
         _CreatedBy = model._CreatedBy,
         _CreatedUtc = model._CreatedUtc,
         _IsDeleted = model._IsDeleted,
         _LastModifiedAgent = model._LastModifiedAgent,
         _LastModifiedBy = model._LastModifiedBy,
         _LastModifiedUtc = model._LastModifiedUtc
     });
 }
        private async Task CreateInventory(FpReturnFromBuyerModel model, string type)
        {
            var inventoryDocument = new InventoryDocument()
            {
                Date          = model.Date,
                Items         = GetInventoryItems(model.Details),
                ReferenceNo   = model.Code,
                ReferenceType = "Return From Buyer",
                StorageCode   = model.StorageCode,
                StorageId     = model.StorageId,
                StorageName   = model.StorageName,
                Type          = type
            };

            await _inventoryDocumentService.Create(inventoryDocument);
        }
        public async Task <int> CreateAsync(FpReturnFromBuyerModel model)
        {
            do
            {
                model.Code = CodeGenerator.GenerateCode();
            }while (_dbSet.Any(d => d.Code.Equals(model.Code)));

            model.FlagForCreate(_identityService.Username, UserAgent);
            foreach (var detail in model.Details)
            {
                detail.FlagForCreate(_identityService.Username, UserAgent);
                foreach (var item in detail.Items)
                {
                    item.FlagForCreate(_identityService.Username, UserAgent);
                    _dbItemSet.Add(item);
                }
                _dbDetailSet.Add(detail);
            }
            _dbSet.Add(model);

            await CreateInventory(model, "IN");

            return(await _dbContext.SaveChangesAsync());
        }
 public Task <int> UpdateAsync(int id, FpReturnFromBuyerModel model)
 {
     throw new NotImplementedException();
 }