private Models.InvoiceViewModels ConverToInvoiceModelView(Invoice xFacturas) { Models.InvoiceViewModels sInv = new Models.InvoiceViewModels(); sInv.InvoiceId = xFacturas.Id; sInv.Type = xFacturas.Type; sInv.InvoiceDetail = ConverToDetailModelView(xFacturas.GetDetail()); return(sInv); }
public ActionResult Create(Models.InvoiceViewModels model, string action) { try { if (action == "generarFactura") { if (model.InvoiceId >= 0) { //Agrego la factura en una variable de sesion para emular el guardado en base de datos if (!facturas.Exists(model.InvoiceId)) { facturas.Insert(model.ToModel()); ActualizarFacturasEnSesion(facturas); } return(Redirect("~Invoice/Index")); } else { throw new Exception("Debe agregar un id para el comprobante"); } } else if (action == "agregarItemFactura") { model.DetailID += model.InvoiceDetail.Count() + 1; // Si no ha pasado nuestra validación, mostramos el mensaje personalizado de error if (!model.NewInvoiceValid()) { throw new Exception("Solo puede agregar un item válido al detalle"); } else if (model.ExistsInDetail(model.DetailDescription)) { throw new Exception("El item elegido ya existe en el detalle"); } else { model.AddItemDetail(); } } else if (action == "retirarFactura") { model.DeleteItemFromDetail(); } else { throw new Exception("Acción no definida .."); } return(View(model)); } catch { return(View(model)); } }
public ActionResult Delete(Models.InvoiceViewModels model, string action) { try { if (action.Equals("aceptar")) { facturas.Delete(model.InvoiceId); ActualizarFacturasEnSesion(facturas); } return(RedirectToAction("Index")); } catch { return(View(model)); } }
public ActionResult DeleteDetail(long xInvoiceId, long xDetailID, Models.InvoiceViewModels xInvoice) { facturas.GetById(xInvoiceId).DeleteDetail(xDetailID); ActualizarFacturasEnSesion(facturas); return(Redirect("~/Invoice/Edit/" + xInvoiceId)); }