public ActionResult UpdateItem(long?idinvoice, long iditem) { try { if (idinvoice == null) { return(View("Error")); } Invoice invoiceToModity = _InvoiceContext.GetById((long)idinvoice); InvoiceDetailViewModels invoiceDetailVM = new InvoiceDetailViewModels(); foreach (var item in invoiceToModity.GetDetail()) { if (item.Id == iditem) { invoiceDetailVM.Id = item.Id; invoiceDetailVM.InvoiceId = item.InvoiceId; invoiceDetailVM.Amount = item.Amount; invoiceDetailVM.Description = item.Description; invoiceDetailVM.TotalPrice = item.TotalPrice; invoiceDetailVM.TotalPriceWithTaxes = item.TotalPriceWithTaxes; invoiceDetailVM.UnitPrice = item.UnitPrice; break; } } return(View(invoiceDetailVM)); } catch (Exception ex) { return(View("Error")); } }
public ActionResult AddItem(InvoiceDetailViewModels invoiceDetailVM) { try { if (this.ModelState.IsValid) { string invoiceForDetail = Request.Form["invoice"]; List <InvoiceDetail> items = new List <InvoiceDetail>(); InvoiceDetail detail = new InvoiceDetail { InvoiceId = invoiceDetailVM.InvoiceId, Amount = invoiceDetailVM.Amount, Description = invoiceDetailVM.Description, UnitPrice = invoiceDetailVM.UnitPrice }; _InvoiceContext.AddDetail(invoiceDetailVM.Id, detail); ViewBag.Invoice = detail.InvoiceId; return(RedirectToAction("Detail", new { id = invoiceDetailVM.InvoiceId })); } return(View(invoiceDetailVM)); } catch { return(View()); } }
public ActionResult DeleteItem(long?idinvoice, long?iditem) { if (idinvoice == null || iditem == null) { return(View("Error")); } try { Invoice _invoice = _InvoiceContext.GetById((long)idinvoice); InvoiceDetailViewModels invoiceDetailVM = new InvoiceDetailViewModels(); foreach (var item in _invoice.GetDetail()) { if (item.Id == iditem) { invoiceDetailVM.Id = item.Id; invoiceDetailVM.InvoiceId = item.InvoiceId; invoiceDetailVM.Amount = item.Amount; invoiceDetailVM.Description = item.Description; invoiceDetailVM.TotalPrice = item.TotalPrice; invoiceDetailVM.TotalPriceWithTaxes = item.TotalPriceWithTaxes; invoiceDetailVM.UnitPrice = item.UnitPrice; } } ViewBag.Invoice = _invoice.Id; return(View(invoiceDetailVM)); } catch (Exception ex) { return(View("Error")); } }
// GET: Invoice/Details/5 public ActionResult Detail(long id) { InvoiceDetailViewModels vm = new InvoiceDetailViewModels(); IEnumerable <InvoiceDetail> invDetails = manager.GetById(id).GetDetail(); IEnumerable <InvoiceDetailViewModels> detailVM = vm.Map(invDetails); return(View(detailVM)); }
public ActionResult DeleteItem(InvoiceDetailViewModels invoiceDetailVM) { try { if (invoiceDetailVM == null) { return(View("Error")); } _InvoiceContext.deleteDetail(invoiceDetailVM.InvoiceId, invoiceDetailVM.Id); return(RedirectToAction("Detail", new { id = invoiceDetailVM.InvoiceId })); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(View("Error")); } }
public ActionResult Detail(long id) { Invoice invoice = _InvoiceContext.GetById(id); List <InvoiceDetailViewModels> invoiceDetailVMList = new List <InvoiceDetailViewModels>(); foreach (var inv in invoice.GetDetail()) { InvoiceDetailViewModels objVM = new InvoiceDetailViewModels(); objVM.Id = inv.Id; objVM.InvoiceId = inv.InvoiceId; objVM.Amount = inv.Amount; objVM.Description = inv.Description; objVM.TotalPrice = inv.TotalPrice; objVM.TotalPriceWithTaxes = inv.TotalPriceWithTaxes; objVM.UnitPrice = inv.UnitPrice; invoiceDetailVMList.Add(objVM); } ViewBag.Results = invoiceDetailVMList.Count; ViewBag.Invoice = id; return(View(invoiceDetailVMList)); }
public ActionResult UpdateItem(InvoiceDetailViewModels invoiceDetailVM) { try { if (this.ModelState.IsValid) { InvoiceDetail invoiceDetailToModify = new InvoiceDetail { Id = invoiceDetailVM.Id, InvoiceId = invoiceDetailVM.InvoiceId, Amount = invoiceDetailVM.Amount, Description = invoiceDetailVM.Description, UnitPrice = invoiceDetailVM.UnitPrice }; _InvoiceContext.UpdateItem(invoiceDetailToModify); } return(RedirectToAction("Detail", new { id = invoiceDetailVM.InvoiceId })); } catch (Exception ex) { return(View("Error", ex.Message)); } }