/// <summary> /// Add InvoiceLine By InvoiceLine /// </summary> /// <param name="invoiceLine"></param> /// <returns></returns> public bool AddInvoiceLine(InvoiceLine invoiceLine) { if (invoiceLine == null) { //empty item new LogManager().Log($"Fail to add invoice line (NULL) to invoice(Id: {InvoiceNumber})"); return(false); } if (LineItems == null) { LineItems = new List <InvoiceLine>(); } if (!LineItems.Any(i => i.InvoiceLineId == invoiceLine.InvoiceLineId)) { //add LineItems.Add(invoiceLine); new LogManager().Log($"Add invoice line (Id: {invoiceLine.InvoiceLineId}) to invoice (Id: {InvoiceNumber})"); return(true); } else { //update var existingItem = LineItems.Where(i => i.InvoiceLineId == invoiceLine.InvoiceLineId).First(); LineItems.Remove(existingItem); LineItems.Add(invoiceLine); new LogManager().Log($"Update invoice line (Id: {invoiceLine.InvoiceLineId}) to invoice (Id: {InvoiceNumber})"); return(false); } }
/// <summary> /// Validates that the order does not have a duplicate product ID in the line items. Throws /// an exception if it does. /// </summary> /// <param name="productId"></param> private void ValidateNotDuplicateProductId(int productId) { if (LineItems.Any(l => l.Key.Id == productId)) { throw new BusinessOrderException($"[!] Duplicate product Id {productId}"); } }
/// <summary> /// GetTotal should return the sum of (Cost * Quantity) for each line item /// </summary> public decimal GetTotal() { if (LineItems != null && LineItems.Any()) { new LogManager().Log($"Get invoice total ({InvoiceNumber}): {LineItems.Select(l => l.Cost).Sum()})"); return(LineItems.Select(l => l.Cost).Sum()); } else { new LogManager().Log($"No Items for invoice ({InvoiceNumber}))"); return(0); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (CustomerId <= 0) { yield return(new ValidationResult($"CustomerId must be positive.", new[] { nameof(CustomerId) })); } if (LineItems == null || !LineItems.Any()) { yield return(new ValidationResult( $"LineItems con no be empty", new[] { nameof(LineItems) })); } }
/// <summary> /// Remove InvoiceLine By InvoiceLineId /// </summary> /// <param name="invoiceLineId"></param> /// <returns></returns> public bool RemoveInvoiceLine(int invoiceLineId) { if (LineItems != null && LineItems.Any(i => i.InvoiceLineId == invoiceLineId)) { LineItems.RemoveAll(i => i.InvoiceLineId == invoiceLineId); new LogManager().Log($"Remove invoice line (Id: {invoiceLineId}))"); return(true); } else { new LogManager().Log($"Fail to remove invoice line (Id: {invoiceLineId}))"); return(false); } }
public virtual async Task <PromotionResult> EvaluatePromotionsAsync() { EnsureCartExists(); var promotionResult = new PromotionResult(); if (!LineItems.IsNullOrEmpty() && !LineItems.Any(i => i.IsReadOnly)) { var evalContext = _mapper.Map <PromotionEvaluationContext>(this); promotionResult = await EvaluatePromotionsAsync(evalContext); } return(promotionResult); }
public long?Process() { if (LineItems == null || !LineItems.Any()) { throw new ArgumentNullException(nameof(LineItems)); } var memberships = LineItems.Where(_ => _ is Membership); foreach (var membership in memberships) { var membershipDAO = _mapper.Map <MembershipDAO>(membership); _customerRepository.ActivateMembership(Customer.Id, membershipDAO); } var physicalProducts = LineItems.Where(_ => _ is PhysicalProduct).Cast <PhysicalProduct>().ToList(); if (physicalProducts.Any()) { return(_shippingSlipGenerator.Generate(physicalProducts)); } return(null); }
public async Task <IActionResult> OnPostAsync() { //Validation Check if (DonationTransaction.AgencyID < 1) { ModelState.AddModelError(nameof(DonationTransaction.AgencyID), "Please select valid donor"); } if (!LineItems.Any()) { ModelState.AddModelError(nameof(LineItems), "Please add at least one line item"); } if (ModelState.GetValidationState("DonationTransaction.TimeStamp") == ModelValidationState.Invalid) { ModelState.AddModelError(nameof(DonationTransaction.TimeStamp), "Please enter a valid date"); } foreach (TransactionLineItem item in LineItems) { if (item.FoodCategoryID < 1) { ModelState.AddModelError("LineItem.FoodCategory", "Please enter valid Food Category"); } if (item.Weight <= 0) { ModelState.AddModelError("LineItem.Weight", "Please enter valid weight greater than 0 and less than " + decimal.MaxValue.ToString()); } if (item.DonationTypeID < 1) { ModelState.AddModelError("LineItem.DonationType", "Please enter valid Donation Type"); } if (item.Cases < 1 && DonationTransaction.FoodCategory == FoodCategoryType.USDA) { ModelState.AddModelError("LineItem.Cases", "Please enter number of cases (1 or more)"); } if (item.Quantity < 1 && DonationTransaction.FoodCategory == FoodCategoryType.Pantry) { ModelState.AddModelError("LineItem.Cases", "Please enter quantity greater than 1"); } } if (!ModelState.IsValid) { ViewModel = new IncomingDonationViewModelcs(); ViewModel.Donors = _context.Agencies .Where(a => a.IsDonor) .Include(a => a.Address) .OrderBy(a => a.AgencyName).ToList(); ViewModel.DonationTypes = _context.DonationTypes.OrderBy(t => t.Type).ToList(); ViewModel.RegularFoodCategories = _context.FoodCategories .Where(f => f.FoodCategoryType == FoodCategoryType.Regular) .OrderBy(f => f.Description).ToList(); ViewModel.USDAFoodCategories = _context.FoodCategories .Where(f => f.FoodCategoryType == FoodCategoryType.USDA) .OrderBy(f => f.Description).ToList(); ViewModel.GroceryFoodCategories = _context.FoodCategories .Where(f => f.FoodCategoryType == FoodCategoryType.Grocery) .OrderBy(f => f.Description).ToList(); ViewModel.PantryPack = _context.FoodCategories.FirstOrDefault(f => f.FoodCategoryType == FoodCategoryType.Pantry); return(Page()); } DonationTransaction.TransactionType = TransactionTypeInOut.In; _context.DonationTransactions.Add(DonationTransaction); await _context.SaveChangesAsync(); foreach (TransactionLineItem item in LineItems) { item.DonationTransactionID = DonationTransaction.DonationTransactionID; if (DonationTransaction.FoodCategory != FoodCategoryType.Pantry) { item.Quantity = null; } if (DonationTransaction.FoodCategory != FoodCategoryType.USDA) { item.Cases = null; } _context.TransactionLineItems.Add(item); } await _context.SaveChangesAsync(); return(RedirectToPage("/Reports/DonationTransactions", "Saved", new { savedID = DonationTransaction.DonationTransactionID })); }