public void CalculatePriceWithDiscount(DetailLineDTO detailLineDTO) { decimal totalPrice = detailLineDTO.UnitPrice * detailLineDTO.Amount; decimal totalPriceWithDiscount = totalPrice - ((totalPrice / 100) * detailLineDTO.Discount); detailLineDTO.TotalWithDiscount = Math.Round(totalPriceWithDiscount, 2); }
public IEnumerable <DetailLineDTO> GetCustomerCart(Guid sessionId) { //Get customer cart details var details = _cartContext.CartSessionDetails.Where(x => x.CartSessionId == sessionId) .Select(x => new { x.ProductId, x.Quantity }) .ToList(); //Get all the products in our customers cart var products = _productContext.Products.Where(x => details.Select(y => y.ProductId).Contains(x.Id)); //Generate a new model to display for the customer on basket page List <DetailLineDTO> detailLines = new List <DetailLineDTO>(); foreach (var product in products) { var detailLine = new DetailLineDTO() { ProductId = product.Id, UnitCost = product.Price, Quantity = details.First(x => x.ProductId == product.Id).Quantity, ProductName = product.Name }; detailLines.Add(detailLine); } return(detailLines); }
public void UpdateDetailLine(DetailLineDTO detailLineDTO) { DetailLine detailLine = _mapper.Mapper().Map <DetailLine>(detailLineDTO); detailLine.InvoiceId = detailLineDTO.InvoiceDTOId; detailLine.Invoice = _invoiceRepository.GetById(detailLine.InvoiceId); _detailLineRepository.UpdateEntity(detailLine); _detailLineRepository.Save(); }
public void CalculatePriceWithDiscountAndVat(DetailLineDTO detailLineDTO) { decimal totalPriceWithDiscountAndVat = detailLineDTO.TotalWithDiscount + ((detailLineDTO.TotalWithDiscount / 100) * detailLineDTO.Vat); detailLineDTO.TotalPriceWithDiscountAndVat = Math.Round(totalPriceWithDiscountAndVat, 2); }
public void DeleteDetailLine(DetailLineDTO detailLineDTO) { DetailLine detailLine = _mapper.Mapper().Map <DetailLine>(detailLineDTO); _detailLineRepository.DeleteEntity(detailLine); }