public ActionResult AddLineItem(int id) { var invoiceRepo = new InvoiceRepository(_context); var invoice = invoiceRepo.GetById(id); var workDoneRepo = new WorkDoneRepository(_context); var workDoneList = workDoneRepo.GetClientWorkDone(invoice.Id); var formModel = new AddLineItem() { WorkDoneList = workDoneList }; return(View(formModel)); }
public LineItem AddALineItem(AddLineItem newLineItem) { var sql = @"INSERT INTO LineItem (CartId,LineItemTypeId,ProductId,Quantity) VALUES (@CartId, @LineItemTypeId, @ProductId, @Quantity)"; using (var db = new SqlConnection(ConnectionString)) { var parameters = new { newLineItem.CartId, newLineItem.LineItemTypeId, newLineItem.ProductId, newLineItem.Quantity, }; var result = db.QueryFirstOrDefault <LineItem>(sql, parameters); return(result); } }
public IActionResult AddLineItem([FromBody] AddLineItem newLineItem) { var cart = _lineItemRepository.GetLineItemsByCartId(newLineItem.CartId); var newQuantity = 0; if (cart.Any()) { if (newLineItem.LineItemTypeId == 1) //Subscription { foreach (LineItem item in cart.Where(i => i.LineItemType == "Subscription" && i.ProductId == newLineItem.ProductId)) // Loop through Cart Sub Item List { newQuantity = item.Quantity + newLineItem.Quantity; _lineItemRepository.UpdateQuantity(item.LineItemId, newQuantity); } if (newQuantity == 0) { _lineItemRepository.AddALineItem(newLineItem); } } if (newLineItem.LineItemTypeId == 2) //Show { foreach (LineItem item in cart.Where(i => i.LineItemType == "Show" && i.ProductId == newLineItem.ProductId)) // Loop through Cart Show Item List { newQuantity = item.Quantity + newLineItem.Quantity; _lineItemRepository.UpdateQuantity(item.LineItemId, newQuantity); } if (newQuantity == 0) { _lineItemRepository.AddALineItem(newLineItem); } } } else { _lineItemRepository.AddALineItem(newLineItem); } return(Ok()); }