Ejemplo n.º 1
0
        public override void UpdateAsync(long id, DOReturnModel model)
        {
            try
            {
                if (model.DOReturnDetails != null)
                {
                    HashSet <long> detailIds = doReturnDetailLogic.GetIds(id);
                    foreach (var itemId in detailIds)
                    {
                        DOReturnDetailModel data = model.DOReturnDetails.FirstOrDefault(prop => prop.Id.Equals(itemId));
                        if (data == null)
                        {
                            var deletedDetail = _dbContext.DOReturnDetails.Include(s => s.DOReturnDetailItems).Include(s => s.DOReturnItems).FirstOrDefault(s => s.Id == itemId);
                            EntityExtension.FlagForDelete(deletedDetail, IdentityService.Username, "sales-service", true);
                            foreach (var detailItem in deletedDetail.DOReturnDetailItems)
                            {
                                EntityExtension.FlagForDelete(detailItem, IdentityService.Username, "sales-service", true);
                            }
                            foreach (var item in deletedDetail.DOReturnItems)
                            {
                                EntityExtension.FlagForDelete(item, IdentityService.Username, "sales-service", true);
                            }
                        }

                        else
                        {
                            doReturnDetailLogic.UpdateAsync(itemId, data);
                        }
                    }

                    foreach (DOReturnDetailModel item in model.DOReturnDetails)
                    {
                        if (item.Id == 0)
                        {
                            doReturnDetailLogic.Create(item);
                        }
                    }
                }

                EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service");
                DbSet.Update(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Mapping_With_AutoMapper_Profiles()
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <DOReturnMapper>();
                cfg.AddProfile <DOReturnDetailMapper>();
                cfg.AddProfile <DOReturnDetailItemMapper>();
                cfg.AddProfile <DOReturnItemMapper>();
            });
            var mapper = configuration.CreateMapper();

            DOReturnViewModel salesInvoiceViewModel = new DOReturnViewModel {
                Id = 1
            };
            DOReturnModel salesInvoiceModel = mapper.Map <DOReturnModel>(salesInvoiceViewModel);

            Assert.Equal(salesInvoiceViewModel.Id, salesInvoiceModel.Id);

            DOReturnDetailViewModel salesInvoiceDetailViewModel = new DOReturnDetailViewModel {
                Id = 1
            };
            DOReturnDetailModel salesInvoiceDetailModel = mapper.Map <DOReturnDetailModel>(salesInvoiceDetailViewModel);

            Assert.Equal(salesInvoiceDetailViewModel.Id, salesInvoiceDetailModel.Id);

            DOReturnDetailItemViewModel salesInvoiceDetailItemViewModel = new DOReturnDetailItemViewModel {
                Id = 1
            };
            DOReturnDetailItemModel salesInvoiceDetailItemModel = mapper.Map <DOReturnDetailItemModel>(salesInvoiceDetailItemViewModel);

            Assert.Equal(salesInvoiceDetailItemViewModel.Id, salesInvoiceDetailItemModel.Id);

            DOReturnItemViewModel salesInvoiceItemViewModel = new DOReturnItemViewModel {
                Id = 1
            };
            DOReturnItemModel salesInvoiceItemModel = mapper.Map <DOReturnItemModel>(salesInvoiceItemViewModel);

            Assert.Equal(salesInvoiceItemViewModel.Id, salesInvoiceItemModel.Id);
        }