示例#1
0
        protected override Bill DoPostPutDto(Client currentClient, BillDTO dto, Bill entity, string path, object param)
        {
            if (entity == null)
            {
                entity = new Bill();
            }
            GetMapper.Map(dto, entity);
            if (dto.Booking != null && dto.Booking.Id != 0)
            {
                entity.Booking = BookingService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Booking, currentClient, path);
            }
            if (dto.BillItems != null)
            {
                BillItemRepository.DeleteRange(entity.BillItems.Where(d => !dto.BillItems.Any(x => x.Id == d.Id)));
                dto.BillItems.ForEach(bitem =>
                {
                    if (entity.BillItems.Count != 0 && bitem.Id != 0 &&
                        entity.BillItems.Find(p => p.Id == bitem.Id) != null)
                    {
                        return;
                    }
                    BillItem toAdd = BillItemService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, bitem, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.BillItems.Add(toAdd);
                    }
                });
            }
            if (dto.PaymentMethods != null)
            {
                PaymentMethodRepository.DeleteRange(entity.PaymentMethods.Where(d => !dto.PaymentMethods.Any(x => x.Id == d.Id)));
                dto.PaymentMethods.ForEach(pm =>
                {
                    if (entity.PaymentMethods.Count != 0 && pm.Id != 0 &&
                        entity.PaymentMethods.Find(p => p.Id == pm.Id) != null)
                    {
                        return;
                    }
                    PaymentMethod toAdd = PaymentMethodService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, pm, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.PaymentMethods.Add(toAdd);
                    }
                });
            }
            if (dto.Supplier != null)
            {
                entity.Supplier = SupplierService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Supplier, currentClient, path);
            }
            return(entity);
        }
示例#2
0
        protected override Product DoPostPutDto(Client currentClient, ProductDTO dto, Product entity, string path, object param)
        {
            if (entity == null)
            {
                entity = new Product();
            }
            else
            {
                if (dto.RefHide == null)
                {
                    dto.RefHide = entity.RefHide;
                }
            }
            GetMapper.Map <ProductDTO, Product>(dto, entity);
            if (dto.BillItemCategory != null)
            {
                entity.BillItemCategory = BillItemCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.BillItemCategory, currentClient, path);
            }
            if (dto.ProductCategory != null)
            {
                entity.ProductCategory = ProductCategoryService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.ProductCategory, currentClient, path);
            }
            if (dto.Supplier != null)
            {
                entity.Supplier = SupplierService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Supplier, currentClient, path);
            }
            if (dto.Tax != null)
            {
                entity.Tax = TaxService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, dto.Tax, currentClient, path);
            }
            if (dto.Documents != null)
            {
                DocumentRepository.DeleteRange(entity.Documents.Where(d => !dto.Documents.Any(x => x.Id == d.Id)));
                dto.Documents.ForEach(document =>
                {
                    if (entity.Documents.Count != 0 && document.Id != 0 &&
                        entity.Documents.Find(p => p.Id == document.Id) != null)
                    {
                        return;
                    }
                    Document toAdd = DocumentService.PreProcessDTOPostPut(validationDictionnary, dto.HomeId, document, currentClient, path);

                    if (toAdd != null)
                    {
                        entity.Documents.Add(toAdd);
                    }
                });
            }
            return(entity);
        }