public async Task <ActionResult <DirectSalesOrder_DirectSalesOrderDTO> > Get([FromBody] DirectSalesOrder_DirectSalesOrderDTO DirectSalesOrder_DirectSalesOrderDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } if (!await HasPermission(DirectSalesOrder_DirectSalesOrderDTO.Id)) { return(Forbid()); } DirectSalesOrder DirectSalesOrder = await DirectSalesOrderService.Get(DirectSalesOrder_DirectSalesOrderDTO.Id); List <TaxType> TaxTypes = await TaxTypeService.List(new TaxTypeFilter { Skip = 0, Take = int.MaxValue, Selects = TaxTypeSelect.ALL }); DirectSalesOrder_DirectSalesOrderDTO = new DirectSalesOrder_DirectSalesOrderDTO(DirectSalesOrder); foreach (var DirectSalesOrderContent in DirectSalesOrder_DirectSalesOrderDTO.DirectSalesOrderContents) { TaxType TaxType = TaxTypes.Where(x => x.Percentage == DirectSalesOrderContent.TaxPercentage).FirstOrDefault(); DirectSalesOrderContent.TaxType = new DirectSalesOrder_TaxTypeDTO(TaxType); } return(DirectSalesOrder_DirectSalesOrderDTO); }
private DirectSalesOrder ConvertDTOToEntity(DirectSalesOrder_DirectSalesOrderDTO DirectSalesOrder_DirectSalesOrderDTO) { DirectSalesOrder DirectSalesOrder = new DirectSalesOrder(); DirectSalesOrder.Id = DirectSalesOrder_DirectSalesOrderDTO.Id; DirectSalesOrder.Code = DirectSalesOrder_DirectSalesOrderDTO.Code; DirectSalesOrder.BuyerStoreId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStoreId; DirectSalesOrder.PhoneNumber = DirectSalesOrder_DirectSalesOrderDTO.PhoneNumber; DirectSalesOrder.StoreAddress = DirectSalesOrder_DirectSalesOrderDTO.StoreAddress; DirectSalesOrder.DeliveryAddress = DirectSalesOrder_DirectSalesOrderDTO.DeliveryAddress; DirectSalesOrder.SaleEmployeeId = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployeeId; DirectSalesOrder.OrganizationId = DirectSalesOrder_DirectSalesOrderDTO.OrganizationId; DirectSalesOrder.OrderDate = DirectSalesOrder_DirectSalesOrderDTO.OrderDate; DirectSalesOrder.DeliveryDate = DirectSalesOrder_DirectSalesOrderDTO.DeliveryDate; DirectSalesOrder.RequestStateId = DirectSalesOrder_DirectSalesOrderDTO.RequestStateId; DirectSalesOrder.EditedPriceStatusId = DirectSalesOrder_DirectSalesOrderDTO.EditedPriceStatusId; DirectSalesOrder.Note = DirectSalesOrder_DirectSalesOrderDTO.Note; DirectSalesOrder.SubTotal = DirectSalesOrder_DirectSalesOrderDTO.SubTotal; DirectSalesOrder.GeneralDiscountPercentage = DirectSalesOrder_DirectSalesOrderDTO.GeneralDiscountPercentage; DirectSalesOrder.GeneralDiscountAmount = DirectSalesOrder_DirectSalesOrderDTO.GeneralDiscountAmount; DirectSalesOrder.TotalTaxAmount = DirectSalesOrder_DirectSalesOrderDTO.TotalTaxAmount; DirectSalesOrder.TotalAfterTax = DirectSalesOrder_DirectSalesOrderDTO.TotalAfterTax; DirectSalesOrder.PromotionCode = DirectSalesOrder_DirectSalesOrderDTO.PromotionCode; DirectSalesOrder.PromotionValue = DirectSalesOrder_DirectSalesOrderDTO.PromotionValue; DirectSalesOrder.Total = DirectSalesOrder_DirectSalesOrderDTO.Total; DirectSalesOrder.BuyerStore = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore == null ? null : new Store { Id = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.Id, Code = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.Code, Name = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.Name, ParentStoreId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.ParentStoreId, OrganizationId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.OrganizationId, StoreTypeId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.StoreTypeId, StoreGroupingId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.StoreGroupingId, Telephone = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.Telephone, ProvinceId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.ProvinceId, DistrictId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.DistrictId, WardId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.WardId, Address = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.Address, DeliveryAddress = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.DeliveryAddress, Latitude = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.Latitude, Longitude = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.Longitude, DeliveryLatitude = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.DeliveryLatitude, DeliveryLongitude = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.DeliveryLongitude, OwnerName = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.OwnerName, OwnerPhone = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.OwnerPhone, OwnerEmail = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.OwnerEmail, TaxCode = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.TaxCode, LegalEntity = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.LegalEntity, StatusId = DirectSalesOrder_DirectSalesOrderDTO.BuyerStore.StatusId, }; DirectSalesOrder.Organization = DirectSalesOrder_DirectSalesOrderDTO.Organization == null ? null : new Organization { Id = DirectSalesOrder_DirectSalesOrderDTO.Organization.Id, Code = DirectSalesOrder_DirectSalesOrderDTO.Organization.Code, Name = DirectSalesOrder_DirectSalesOrderDTO.Organization.Name, ParentId = DirectSalesOrder_DirectSalesOrderDTO.Organization.ParentId, Path = DirectSalesOrder_DirectSalesOrderDTO.Organization.Path, Level = DirectSalesOrder_DirectSalesOrderDTO.Organization.Level, StatusId = DirectSalesOrder_DirectSalesOrderDTO.Organization.StatusId, Phone = DirectSalesOrder_DirectSalesOrderDTO.Organization.Phone, Address = DirectSalesOrder_DirectSalesOrderDTO.Organization.Address, Email = DirectSalesOrder_DirectSalesOrderDTO.Organization.Email, }; DirectSalesOrder.EditedPriceStatus = DirectSalesOrder_DirectSalesOrderDTO.EditedPriceStatus == null ? null : new EditedPriceStatus { Id = DirectSalesOrder_DirectSalesOrderDTO.EditedPriceStatus.Id, Code = DirectSalesOrder_DirectSalesOrderDTO.EditedPriceStatus.Code, Name = DirectSalesOrder_DirectSalesOrderDTO.EditedPriceStatus.Name, }; DirectSalesOrder.SaleEmployee = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee == null ? null : new AppUser { Id = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Id, Username = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Username, DisplayName = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.DisplayName, Address = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Address, Email = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Email, Phone = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Phone, PositionId = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.PositionId, Department = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Department, OrganizationId = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.OrganizationId, SexId = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.SexId, StatusId = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.StatusId, Avatar = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Avatar, Birthday = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.Birthday, ProvinceId = DirectSalesOrder_DirectSalesOrderDTO.SaleEmployee.ProvinceId, }; DirectSalesOrder.DirectSalesOrderContents = DirectSalesOrder_DirectSalesOrderDTO.DirectSalesOrderContents? .Select(x => new DirectSalesOrderContent { Id = x.Id, ItemId = x.ItemId, UnitOfMeasureId = x.UnitOfMeasureId, Quantity = x.Quantity, PrimaryUnitOfMeasureId = x.PrimaryUnitOfMeasureId, RequestedQuantity = x.RequestedQuantity, PrimaryPrice = x.PrimaryPrice, SalePrice = x.SalePrice, DiscountPercentage = x.DiscountPercentage, DiscountAmount = x.DiscountAmount, GeneralDiscountPercentage = x.GeneralDiscountPercentage, GeneralDiscountAmount = x.GeneralDiscountAmount, Amount = x.Amount, TaxPercentage = x.TaxPercentage, TaxAmount = x.TaxAmount, Factor = x.Factor, Item = x.Item == null ? null : new Item { Id = x.Item.Id, Code = x.Item.Code, Name = x.Item.Name, ProductId = x.Item.ProductId, RetailPrice = x.Item.RetailPrice, SalePrice = x.Item.SalePrice, SaleStock = x.Item.SaleStock, ScanCode = x.Item.ScanCode, StatusId = x.Item.StatusId, Product = x.Item.Product == null ? null : new Product { Id = x.Item.Product.Id, Code = x.Item.Product.Code, SupplierCode = x.Item.Product.SupplierCode, Name = x.Item.Product.Name, Description = x.Item.Product.Description, ScanCode = x.Item.Product.ScanCode, ProductTypeId = x.Item.Product.ProductTypeId, SupplierId = x.Item.Product.SupplierId, BrandId = x.Item.Product.BrandId, UnitOfMeasureId = x.Item.Product.UnitOfMeasureId, UnitOfMeasureGroupingId = x.Item.Product.UnitOfMeasureGroupingId, RetailPrice = x.Item.Product.RetailPrice, TaxTypeId = x.Item.Product.TaxTypeId, StatusId = x.Item.Product.StatusId, ProductType = x.Item.Product.ProductType == null ? null : new ProductType { Id = x.Item.Product.ProductType.Id, Code = x.Item.Product.ProductType.Code, Name = x.Item.Product.ProductType.Name, Description = x.Item.Product.ProductType.Description, StatusId = x.Item.Product.ProductType.StatusId, }, TaxType = x.Item.Product.TaxType == null ? null : new TaxType { Id = x.Item.Product.TaxType.Id, Code = x.Item.Product.TaxType.Code, StatusId = x.Item.Product.TaxType.StatusId, Name = x.Item.Product.TaxType.Name, Percentage = x.Item.Product.TaxType.Percentage, }, UnitOfMeasure = x.Item.Product.UnitOfMeasure == null ? null : new UnitOfMeasure { Id = x.Item.Product.UnitOfMeasure.Id, Code = x.Item.Product.UnitOfMeasure.Code, Name = x.Item.Product.UnitOfMeasure.Name, Description = x.Item.Product.UnitOfMeasure.Description, StatusId = x.Item.Product.UnitOfMeasure.StatusId, }, UnitOfMeasureGrouping = x.Item.Product.UnitOfMeasureGrouping == null ? null : new UnitOfMeasureGrouping { Id = x.Item.Product.UnitOfMeasureGrouping.Id, Code = x.Item.Product.UnitOfMeasureGrouping.Code, Name = x.Item.Product.UnitOfMeasureGrouping.Name, Description = x.Item.Product.UnitOfMeasureGrouping.Description, UnitOfMeasureId = x.Item.Product.UnitOfMeasureGrouping.UnitOfMeasureId, }, } }, PrimaryUnitOfMeasure = x.PrimaryUnitOfMeasure == null ? null : new UnitOfMeasure { Id = x.PrimaryUnitOfMeasure.Id, Code = x.PrimaryUnitOfMeasure.Code, Name = x.PrimaryUnitOfMeasure.Name, Description = x.PrimaryUnitOfMeasure.Description, StatusId = x.PrimaryUnitOfMeasure.StatusId, }, UnitOfMeasure = x.UnitOfMeasure == null ? null : new UnitOfMeasure { Id = x.UnitOfMeasure.Id, Code = x.UnitOfMeasure.Code, Name = x.UnitOfMeasure.Name, Description = x.UnitOfMeasure.Description, StatusId = x.UnitOfMeasure.StatusId, }, }).ToList(); DirectSalesOrder.DirectSalesOrderPromotions = DirectSalesOrder_DirectSalesOrderDTO.DirectSalesOrderPromotions? .Select(x => new DirectSalesOrderPromotion { Id = x.Id, ItemId = x.ItemId, UnitOfMeasureId = x.UnitOfMeasureId, Quantity = x.Quantity, PrimaryUnitOfMeasureId = x.PrimaryUnitOfMeasureId, RequestedQuantity = x.RequestedQuantity, Note = x.Note, Factor = x.Factor, Item = x.Item == null ? null : new Item { Id = x.Item.Id, ProductId = x.Item.ProductId, Code = x.Item.Code, Name = x.Item.Name, ScanCode = x.Item.ScanCode, SalePrice = x.Item.SalePrice, RetailPrice = x.Item.RetailPrice, StatusId = x.Item.StatusId, SaleStock = x.Item.SaleStock, Product = x.Item.Product == null ? null : new Product { Id = x.Item.Product.Id, Code = x.Item.Product.Code, SupplierCode = x.Item.Product.SupplierCode, Name = x.Item.Product.Name, Description = x.Item.Product.Description, ScanCode = x.Item.Product.ScanCode, ProductTypeId = x.Item.Product.ProductTypeId, SupplierId = x.Item.Product.SupplierId, BrandId = x.Item.Product.BrandId, UnitOfMeasureId = x.Item.Product.UnitOfMeasureId, UnitOfMeasureGroupingId = x.Item.Product.UnitOfMeasureGroupingId, RetailPrice = x.Item.Product.RetailPrice, TaxTypeId = x.Item.Product.TaxTypeId, StatusId = x.Item.Product.StatusId, ProductType = x.Item.Product.ProductType == null ? null : new ProductType { Id = x.Item.Product.ProductType.Id, Code = x.Item.Product.ProductType.Code, Name = x.Item.Product.ProductType.Name, Description = x.Item.Product.ProductType.Description, StatusId = x.Item.Product.ProductType.StatusId, }, TaxType = x.Item.Product.TaxType == null ? null : new TaxType { Id = x.Item.Product.TaxType.Id, Code = x.Item.Product.TaxType.Code, StatusId = x.Item.Product.TaxType.StatusId, Name = x.Item.Product.TaxType.Name, Percentage = x.Item.Product.TaxType.Percentage, }, UnitOfMeasure = x.Item.Product.UnitOfMeasure == null ? null : new UnitOfMeasure { Id = x.Item.Product.UnitOfMeasure.Id, Code = x.Item.Product.UnitOfMeasure.Code, Name = x.Item.Product.UnitOfMeasure.Name, Description = x.Item.Product.UnitOfMeasure.Description, StatusId = x.Item.Product.UnitOfMeasure.StatusId, }, UnitOfMeasureGrouping = x.Item.Product.UnitOfMeasureGrouping == null ? null : new UnitOfMeasureGrouping { Id = x.Item.Product.UnitOfMeasureGrouping.Id, Code = x.Item.Product.UnitOfMeasureGrouping.Code, Name = x.Item.Product.UnitOfMeasureGrouping.Name, Description = x.Item.Product.UnitOfMeasureGrouping.Description, UnitOfMeasureId = x.Item.Product.UnitOfMeasureGrouping.UnitOfMeasureId, }, } }, PrimaryUnitOfMeasure = x.PrimaryUnitOfMeasure == null ? null : new UnitOfMeasure { Id = x.PrimaryUnitOfMeasure.Id, Code = x.PrimaryUnitOfMeasure.Code, Name = x.PrimaryUnitOfMeasure.Name, Description = x.PrimaryUnitOfMeasure.Description, StatusId = x.PrimaryUnitOfMeasure.StatusId, }, UnitOfMeasure = x.UnitOfMeasure == null ? null : new UnitOfMeasure { Id = x.UnitOfMeasure.Id, Code = x.UnitOfMeasure.Code, Name = x.UnitOfMeasure.Name, Description = x.UnitOfMeasure.Description, StatusId = x.UnitOfMeasure.StatusId, }, }).ToList(); DirectSalesOrder.BaseLanguage = CurrentContext.Language; return(DirectSalesOrder); }