private async Task <bool> ValidateItem(CustomerSalesOrder CustomerSalesOrder) { if (CustomerSalesOrder.CustomerSalesOrderPromotions != null) { var Ids = CustomerSalesOrder.CustomerSalesOrderPromotions.Select(x => x.ItemId).ToList(); var ItemFilter = new ItemFilter { Skip = 0, Take = int.MaxValue, Id = new IdFilter { In = Ids }, StatusId = new IdFilter { Equal = Enums.StatusEnum.ACTIVE.Id }, Selects = ItemSelect.Id }; var listIdsInDB = (await UOW.ItemRepository.List(ItemFilter)).Select(x => x.Id); var listIdsNotExisted = Ids.Except(listIdsInDB); foreach (var CustomerSalesOrderPromotion in CustomerSalesOrder.CustomerSalesOrderPromotions) { if (listIdsNotExisted.Contains(CustomerSalesOrderPromotion.ItemId)) { CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderValidator), nameof(CustomerSalesOrderPromotion.Item), ErrorCode.ItemNotExisted); } } } return(CustomerSalesOrder.IsValidated); }
public async Task <bool> Delete(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { if (await ValidateId(CustomerSalesOrderPromotion)) { } return(CustomerSalesOrderPromotion.IsValidated); }
public async Task <CustomerSalesOrderPromotion> Get(long Id) { CustomerSalesOrderPromotion CustomerSalesOrderPromotion = await UOW.CustomerSalesOrderPromotionRepository.Get(Id); if (CustomerSalesOrderPromotion == null) { return(null); } return(CustomerSalesOrderPromotion); }
public Company_CustomerSalesOrderPromotionDTO(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { this.Id = CustomerSalesOrderPromotion.Id; this.CustomerSalesOrderId = CustomerSalesOrderPromotion.CustomerSalesOrderId; this.ItemId = CustomerSalesOrderPromotion.ItemId; this.UnitOfMeasureId = CustomerSalesOrderPromotion.UnitOfMeasureId; this.Quantity = CustomerSalesOrderPromotion.Quantity; this.RequestedQuantity = CustomerSalesOrderPromotion.RequestedQuantity; this.PrimaryUnitOfMeasureId = CustomerSalesOrderPromotion.PrimaryUnitOfMeasureId; this.Factor = CustomerSalesOrderPromotion.Factor; this.Note = CustomerSalesOrderPromotion.Note; this.Item = CustomerSalesOrderPromotion.Item == null ? null : new Company_ItemDTO(CustomerSalesOrderPromotion.Item); this.PrimaryUnitOfMeasure = CustomerSalesOrderPromotion.PrimaryUnitOfMeasure == null ? null : new Company_UnitOfMeasureDTO(CustomerSalesOrderPromotion.PrimaryUnitOfMeasure); this.UnitOfMeasure = CustomerSalesOrderPromotion.UnitOfMeasure == null ? null : new Company_UnitOfMeasureDTO(CustomerSalesOrderPromotion.UnitOfMeasure); this.Errors = CustomerSalesOrderPromotion.Errors; }
public async Task <bool> ValidateId(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { CustomerSalesOrderPromotionFilter CustomerSalesOrderPromotionFilter = new CustomerSalesOrderPromotionFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = CustomerSalesOrderPromotion.Id }, Selects = CustomerSalesOrderPromotionSelect.Id }; int count = await UOW.CustomerSalesOrderPromotionRepository.Count(CustomerSalesOrderPromotionFilter); if (count == 0) { CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderPromotionValidator), nameof(CustomerSalesOrderPromotion.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <bool> Create(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { CustomerSalesOrderPromotionDAO CustomerSalesOrderPromotionDAO = new CustomerSalesOrderPromotionDAO(); CustomerSalesOrderPromotionDAO.Id = CustomerSalesOrderPromotion.Id; CustomerSalesOrderPromotionDAO.CustomerSalesOrderId = CustomerSalesOrderPromotion.CustomerSalesOrderId; CustomerSalesOrderPromotionDAO.ItemId = CustomerSalesOrderPromotion.ItemId; CustomerSalesOrderPromotionDAO.UnitOfMeasureId = CustomerSalesOrderPromotion.UnitOfMeasureId; CustomerSalesOrderPromotionDAO.Quantity = CustomerSalesOrderPromotion.Quantity; CustomerSalesOrderPromotionDAO.RequestedQuantity = CustomerSalesOrderPromotion.RequestedQuantity; CustomerSalesOrderPromotionDAO.PrimaryUnitOfMeasureId = CustomerSalesOrderPromotion.PrimaryUnitOfMeasureId; CustomerSalesOrderPromotionDAO.Factor = CustomerSalesOrderPromotion.Factor; CustomerSalesOrderPromotionDAO.Note = CustomerSalesOrderPromotion.Note; DataContext.CustomerSalesOrderPromotion.Add(CustomerSalesOrderPromotionDAO); await DataContext.SaveChangesAsync(); CustomerSalesOrderPromotion.Id = CustomerSalesOrderPromotionDAO.Id; await SaveReference(CustomerSalesOrderPromotion); return(true); }
public async Task <CustomerSalesOrderPromotion> Delete(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { if (!await CustomerSalesOrderPromotionValidator.Delete(CustomerSalesOrderPromotion)) { return(CustomerSalesOrderPromotion); } try { await UOW.CustomerSalesOrderPromotionRepository.Delete(CustomerSalesOrderPromotion); await Logging.CreateAuditLog(new { }, CustomerSalesOrderPromotion, nameof(CustomerSalesOrderPromotionService)); return(CustomerSalesOrderPromotion); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CustomerSalesOrderPromotionService)); } return(null); }
private async Task <bool> ValidatePromotion(CustomerSalesOrder CustomerSalesOrder) { if (CustomerSalesOrder.CustomerSalesOrderPromotions != null) { await ValidateItem(CustomerSalesOrder); //validate đơn vị tính sản phẩm khuyến mãi var Ids = CustomerSalesOrder.CustomerSalesOrderPromotions.Select(x => x.UnitOfMeasureId).ToList(); var UnitOfMeasureFilter = new UnitOfMeasureFilter { Skip = 0, Take = int.MaxValue, Id = new IdFilter { In = Ids }, StatusId = new IdFilter { Equal = Enums.StatusEnum.ACTIVE.Id }, Selects = UnitOfMeasureSelect.Id }; var listIdsInDB = (await UOW.UnitOfMeasureRepository.List(UnitOfMeasureFilter)).Select(x => x.Id); var listIdsNotExisted = Ids.Except(listIdsInDB); foreach (var CustomerSalesOrderPromotion in CustomerSalesOrder.CustomerSalesOrderPromotions) { if (listIdsNotExisted.Contains(CustomerSalesOrderPromotion.UnitOfMeasureId)) { CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderValidator), nameof(CustomerSalesOrderPromotion.UnitOfMeasure), ErrorCode.UnitOfMeasureEmpty); } //validate số lượng if (CustomerSalesOrderPromotion.Quantity <= 0) { CustomerSalesOrderPromotion.AddError(nameof(CustomerSalesOrderValidator), nameof(CustomerSalesOrderPromotion.Quantity), ErrorCode.QuantityEmpty); } } } return(CustomerSalesOrder.IsValidated); }
public async Task <bool> Update(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { CustomerSalesOrderPromotionDAO CustomerSalesOrderPromotionDAO = DataContext.CustomerSalesOrderPromotion.Where(x => x.Id == CustomerSalesOrderPromotion.Id).FirstOrDefault(); if (CustomerSalesOrderPromotionDAO == null) { return(false); } CustomerSalesOrderPromotionDAO.Id = CustomerSalesOrderPromotion.Id; CustomerSalesOrderPromotionDAO.CustomerSalesOrderId = CustomerSalesOrderPromotion.CustomerSalesOrderId; CustomerSalesOrderPromotionDAO.ItemId = CustomerSalesOrderPromotion.ItemId; CustomerSalesOrderPromotionDAO.UnitOfMeasureId = CustomerSalesOrderPromotion.UnitOfMeasureId; CustomerSalesOrderPromotionDAO.Quantity = CustomerSalesOrderPromotion.Quantity; CustomerSalesOrderPromotionDAO.RequestedQuantity = CustomerSalesOrderPromotion.RequestedQuantity; CustomerSalesOrderPromotionDAO.PrimaryUnitOfMeasureId = CustomerSalesOrderPromotion.PrimaryUnitOfMeasureId; CustomerSalesOrderPromotionDAO.Factor = CustomerSalesOrderPromotion.Factor; CustomerSalesOrderPromotionDAO.Note = CustomerSalesOrderPromotion.Note; await DataContext.SaveChangesAsync(); await SaveReference(CustomerSalesOrderPromotion); return(true); }
public async Task <CustomerSalesOrderPromotion> Update(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { if (!await CustomerSalesOrderPromotionValidator.Update(CustomerSalesOrderPromotion)) { return(CustomerSalesOrderPromotion); } try { var oldData = await UOW.CustomerSalesOrderPromotionRepository.Get(CustomerSalesOrderPromotion.Id); await UOW.CustomerSalesOrderPromotionRepository.Update(CustomerSalesOrderPromotion); CustomerSalesOrderPromotion = await UOW.CustomerSalesOrderPromotionRepository.Get(CustomerSalesOrderPromotion.Id); await Logging.CreateAuditLog(CustomerSalesOrderPromotion, oldData, nameof(CustomerSalesOrderPromotionService)); return(CustomerSalesOrderPromotion); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CustomerSalesOrderPromotionService)); } return(null); }
public async Task <bool> Create(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { return(CustomerSalesOrderPromotion.IsValidated); }
private async Task SaveReference(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { }
public async Task <bool> Delete(CustomerSalesOrderPromotion CustomerSalesOrderPromotion) { await DataContext.CustomerSalesOrderPromotion.Where(x => x.Id == CustomerSalesOrderPromotion.Id).DeleteFromQueryAsync(); return(true); }
public async Task <CustomerSalesOrderPromotion> Get(long Id) { CustomerSalesOrderPromotion CustomerSalesOrderPromotion = await DataContext.CustomerSalesOrderPromotion.AsNoTracking() .Where(x => x.Id == Id) .Select(x => new CustomerSalesOrderPromotion() { Id = x.Id, CustomerSalesOrderId = x.CustomerSalesOrderId, ItemId = x.ItemId, UnitOfMeasureId = x.UnitOfMeasureId, Quantity = x.Quantity, RequestedQuantity = x.RequestedQuantity, PrimaryUnitOfMeasureId = x.PrimaryUnitOfMeasureId, Factor = x.Factor, Note = x.Note, CustomerSalesOrder = x.CustomerSalesOrder == null ? null : new CustomerSalesOrder { Id = x.CustomerSalesOrder.Id, Code = x.CustomerSalesOrder.Code, CustomerTypeId = x.CustomerSalesOrder.CustomerTypeId, CustomerId = x.CustomerSalesOrder.CustomerId, OpportunityId = x.CustomerSalesOrder.OpportunityId, ContractId = x.CustomerSalesOrder.ContractId, OrderPaymentStatusId = x.CustomerSalesOrder.OrderPaymentStatusId, RequestStateId = x.CustomerSalesOrder.RequestStateId, EditedPriceStatusId = x.CustomerSalesOrder.EditedPriceStatusId, ShippingName = x.CustomerSalesOrder.ShippingName, OrderDate = x.CustomerSalesOrder.OrderDate, DeliveryDate = x.CustomerSalesOrder.DeliveryDate, SalesEmployeeId = x.CustomerSalesOrder.SalesEmployeeId, Note = x.CustomerSalesOrder.Note, InvoiceAddress = x.CustomerSalesOrder.InvoiceAddress, InvoiceNationId = x.CustomerSalesOrder.InvoiceNationId, InvoiceProvinceId = x.CustomerSalesOrder.InvoiceProvinceId, InvoiceDistrictId = x.CustomerSalesOrder.InvoiceDistrictId, InvoiceWardId = x.CustomerSalesOrder.InvoiceWardId, InvoiceZIPCode = x.CustomerSalesOrder.InvoiceZIPCode, DeliveryAddress = x.CustomerSalesOrder.DeliveryAddress, DeliveryNationId = x.CustomerSalesOrder.DeliveryNationId, DeliveryProvinceId = x.CustomerSalesOrder.DeliveryProvinceId, DeliveryDistrictId = x.CustomerSalesOrder.DeliveryDistrictId, DeliveryWardId = x.CustomerSalesOrder.DeliveryWardId, DeliveryZIPCode = x.CustomerSalesOrder.DeliveryZIPCode, SubTotal = x.CustomerSalesOrder.SubTotal, GeneralDiscountPercentage = x.CustomerSalesOrder.GeneralDiscountPercentage, GeneralDiscountAmount = x.CustomerSalesOrder.GeneralDiscountAmount, TotalTaxOther = x.CustomerSalesOrder.TotalTaxOther, TotalTax = x.CustomerSalesOrder.TotalTax, Total = x.CustomerSalesOrder.Total, CreatorId = x.CustomerSalesOrder.CreatorId, OrganizationId = x.CustomerSalesOrder.OrganizationId, RowId = x.CustomerSalesOrder.RowId, }, 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, Used = x.Item.Used, RowId = x.Item.RowId, }, 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, Used = x.PrimaryUnitOfMeasure.Used, RowId = x.PrimaryUnitOfMeasure.RowId, }, 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, Used = x.UnitOfMeasure.Used, RowId = x.UnitOfMeasure.RowId, }, }).FirstOrDefaultAsync(); if (CustomerSalesOrderPromotion == null) { return(null); } return(CustomerSalesOrderPromotion); }