public async Task <CreateProcessStatus> CreatePackingSlipDetailsByView(PackingSlipView view)
        {
            try
            {
                PackingSlip packingSlip = await(from e in _dbContext.PackingSlips
                                                where e.SlipDocument == view.SlipDocument
                                                select e).FirstOrDefaultAsync <PackingSlip>();

                if (packingSlip != null)
                {
                    long packingSlipId = packingSlip.PackingSlipId;

                    foreach (var detail in view.PackingSlipDetailViews)
                    {
                        detail.PackingSlipId = packingSlipId;

                        PackingSlipDetail newDetail = new PackingSlipDetail();
                        applicationViewFactory.MapPackingSlipDetailEntity(ref newDetail, detail);

                        var queryDetail = await(from e in _dbContext.PackingSlipDetails
                                                where e.ItemId == detail.ItemId &&
                                                e.PackingSlipId == newDetail.PackingSlipId
                                                select e).FirstOrDefaultAsync <PackingSlipDetail>();
                        if (queryDetail == null)
                        {
                            _dbContext.Set <PackingSlipDetail>().Add(newDetail);
                        }
                    }
                    return(CreateProcessStatus.Insert);
                }
                return(CreateProcessStatus.AlreadyExists);
            }
            catch (Exception ex) { throw new Exception(GetMyMethodName(), ex); }
        }
        public async Task <CreateProcessStatus> CreatePackingSlipByView(PackingSlipView view)
        {
            decimal amount = 0;

            try
            {
                //check if packing slip exists
                var query = await(from e in _dbContext.PackingSlips
                                  where e.SlipDocument == view.SlipDocument

                                  select e).FirstOrDefaultAsync <PackingSlip>();
                if (query != null)
                {
                    return(CreateProcessStatus.AlreadyExists);
                }


                foreach (var detail in view.PackingSlipDetailViews)
                {
                    amount += detail.ExtendedCost ?? 0;
                }
                view.Amount = amount;

                PackingSlip packingSlip = new PackingSlip();
                applicationViewFactory.MapPackingSlipEntity(ref packingSlip, view);

                base.AddObject(packingSlip);


                return(CreateProcessStatus.Insert);
            }
            catch (Exception ex) { throw new Exception(GetMyMethodName(), ex); }
        }
        public async Task <PackingSlipView> GetPackingSlipViewBySlipDocument(string slipDocument)
        {
            try
            {
                List <PackingSlip> list = await GetObjectsQueryable(e => e.SlipDocument == slipDocument).ToListAsync <PackingSlip>();

                PackingSlipView view = applicationViewFactory.MapPackingSlipView(list[0]);

                var query = await(from e in _dbContext.PackingSlipDetails
                                  where e.PackingSlipId == view.PackingSlipId
                                  select e).ToListAsync <PackingSlipDetail>();
                foreach (var item in query)
                {
                    view.PackingSlipDetailViews.Add(applicationViewFactory.MapPackingSlipDetailView(item));
                }
                return(view);
            }
            catch (Exception ex)
            { throw new Exception(GetMyMethodName(), ex); }
        }