public static bool EditarFacturaProducto(FacturaProducto facturaProducto) { bool response = false; try { using (var dbContextScope = new DigitalWareEntities()) { var facturaProductoConsulta = dbContextScope.FacturaProducto.Where(x => x.Id == facturaProducto.Id).FirstOrDefault(); if (facturaProductoConsulta != null) { FrammeworkTypeUtility.SetProperties(facturaProducto, facturaProductoConsulta); dbContextScope.SaveChanges(); response = true; } } } catch (Exception ex) { response = false; throw ex; } return(response); }
public static FacturaProductoResponse EliminarFacturaProducto(FacturaModel request) { var mensajes = new List <Mensaje>(); try { // No tiene errores if (mensajes.Count == 0) { FacturaProducto facturaProducto = ConfigAutomapper.mapper.Map <FacturaProducto>(request); FacturaAccess.EliminarFacturaProducto(facturaProducto.Id); FacturaProductoModel facturaProductoModel = ConfigAutomapper.mapper.Map <FacturaProductoModel>(facturaProducto); mensajes.Add(new Mensaje("1", "Registro Creado Correctamente")); return(new FacturaProductoResponse(facturaProductoModel, true, mensajes)); } else { return(new FacturaProductoResponse(null, false, mensajes)); } } catch (Exception ex) { //Captura de errores mensajes.Add(new Mensaje("Error", ex.Message)); return(new FacturaProductoResponse(null, false, mensajes)); } }
public void InsertarFacturaProducto(FacturaProducto facturaProducto) { using (var bd = this) { try { bd.IniciarTransaccion(); SqlCommand comando = new SqlCommand(); comando.Connection = bd.Conexion; comando.Transaction = bd.Transaccion; comando.CommandType = CommandType.StoredProcedure; comando.CommandText = "facturacion.InsertarFacturaProducto"; comando.Parameters.Add(new SqlParameter("@cantidad", facturaProducto.Cantidad)); comando.Parameters.Add(new SqlParameter("@idFactura", facturaProducto.Factura.IdFactura)); comando.Parameters.Add(new SqlParameter("@idProducto", facturaProducto.Producto.IdProducto)); comando.ExecuteNonQuery(); bd.ConfirmarTransaccion(); } catch (Exception) { bd.RevertirTransaccion(); throw; } } }
public List <FacturaProducto> ListarFacturaProductos() { List <FacturaProducto> facturaProductos = new List <FacturaProducto>(); using (var bd = this) { try { bd.IniciarTransaccion(); SqlDataReader reader; SqlCommand comando = new SqlCommand(); comando.Connection = bd.Conexion; comando.Transaction = bd.Transaccion; comando.CommandType = CommandType.StoredProcedure; comando.CommandText = "facturacion.ListarFacturaProducto"; reader = comando.ExecuteReader(); try { FacturaProducto facturaProducto; while (reader.Read()) { facturaProducto = new FacturaProducto() { Cantidad = Convert.ToInt32(reader["Cantidad"]), Factura = new Factura() { IdFactura = Convert.ToInt32(reader["IdFactura"]) }, Producto = new Producto() { IdProducto = Convert.ToInt32(reader["IdProducto"]) } }; facturaProductos.Add(facturaProducto); } ; } finally { try { reader.Close(); } catch (Exception e) { throw e; } } bd.ConfirmarTransaccion(); } catch (Exception) { bd.RevertirTransaccion(); throw; } } return(facturaProductos); }
public ActionResult DeleteConfirmed(int id) { FacturaProducto facturaProducto = db.FacturaProductos.Find(id); db.FacturaProductos.Remove(facturaProducto); db.SaveChanges(); log.Info("Eliminacion de factura producto"); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,IdCliente,IdProducto,Cantidad,Fecha,Monto")] FacturaProducto facturaProducto) { if (ModelState.IsValid) { db.Entry(facturaProducto).State = EntityState.Modified; db.SaveChanges(); log.Info("Edicion de factura producto"); return(RedirectToAction("Index")); } ViewBag.IdCliente = new SelectList(db.Clientes, "Id", "NombreCompleto", facturaProducto.IdCliente); ViewBag.IdProducto = new SelectList(db.Productos, "Id", "Nombre", facturaProducto.IdProducto); return(View(facturaProducto)); }
public FacturaProducto ObtenerFacturaProducto(int idFactura, int idProducto) { FacturaProducto facturaProducto = new FacturaProducto(); using (var bd = this) { try { bd.IniciarTransaccion(); SqlDataReader reader; SqlCommand comando = new SqlCommand(); comando.Connection = bd.Conexion; comando.Transaction = bd.Transaccion; comando.CommandType = CommandType.StoredProcedure; comando.CommandText = "facturacion.ObtenerFacturaProducto"; comando.Parameters.Add(new SqlParameter("@idFactura", idFactura)); comando.Parameters.Add(new SqlParameter("@idProducto", idProducto)); reader = comando.ExecuteReader(); try { if (reader.Read()) { facturaProducto.Cantidad = Convert.ToInt32(reader["Cantidad"]); facturaProducto.Factura = new Factura() { IdFactura = Convert.ToInt32(reader["IdFactura"]) }; facturaProducto.Producto = new Producto() { IdProducto = Convert.ToInt32(reader["IdProducto"]) }; } } finally { reader.Close(); } bd.ConfirmarTransaccion(); } catch (Exception) { bd.RevertirTransaccion(); throw; } } return(facturaProducto); }
// GET: FacturaProducto/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FacturaProducto facturaProducto = db.FacturaProductos.Find(id); if (facturaProducto == null) { return(HttpNotFound()); } return(View(facturaProducto)); }
public async Task <bool> FacturaProductoDelete(FacturaProducto facturaProducto) { using (var conn = new SqlConnection(_configuration.Value)) { var parameters = new DynamicParameters(); parameters.Add("IdFactura", facturaProducto.IdFactura, DbType.Int32); parameters.Add("IdProducto", facturaProducto.IdProducto, DbType.Int32); var query = @"DELETE FROM Factura_Producto WHERE IdFactura=@IdFactura AND IdProducto=@IdProducto"; await conn.ExecuteAsync(query.ToString(), new { facturaProducto.IdFactura, facturaProducto.IdProducto }, commandType : CommandType.Text); } return(true); }
public async Task <bool> FacturaProductoInsert(FacturaProducto facturaProducto) { using (var conn = new SqlConnection(_configuration.Value)) { var parameters = new DynamicParameters(); parameters.Add("IdFactura", facturaProducto.IdFactura, DbType.Int32); parameters.Add("IdProducto", facturaProducto.IdProducto, DbType.Int32); parameters.Add("ValorProducto", facturaProducto.ValorProducto, DbType.Decimal); parameters.Add("CantidadProducto", facturaProducto.CantidadProducto, DbType.Decimal); const string query = @"INSERT INTO Factura_Producto (IdFactura, IdProducto, ValorProducto, CantidadProducto) VALUES (@IdFactura, @IdProducto, @ValorProducto, @CantidadProducto)"; await conn.ExecuteAsync(query, new { facturaProducto.IdFactura, facturaProducto.IdProducto, facturaProducto.ValorProducto, facturaProducto.CantidadProducto }, commandType : CommandType.Text); } return(true); }
// GET: FacturaProducto/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FacturaProducto facturaProducto = db.FacturaProductos.Find(id); if (facturaProducto == null) { return(HttpNotFound()); } ViewBag.IdCliente = new SelectList(db.Clientes, "Id", "NombreCompleto", facturaProducto.IdCliente); ViewBag.IdProducto = new SelectList(db.Productos, "Id", "Nombre", facturaProducto.IdProducto); return(View(facturaProducto)); }
public async Task <bool> FacturaProductoUpdate(FacturaProducto facturaProducto) { using (var conn = new SqlConnection(_configuration.Value)) { var parameters = new DynamicParameters(); parameters.Add("IdFactura", facturaProducto.IdFactura, DbType.Int32); parameters.Add("IdProducto", facturaProducto.IdProducto, DbType.Int32); parameters.Add("ValorProducto", facturaProducto.ValorProducto, DbType.Decimal); parameters.Add("CantidadProducto", facturaProducto.CantidadProducto, DbType.Decimal); const string query = @"UPDATE Factura_Producto SET ValorProducto = @ValorProducto, CantidadProducto = @CantidadProducto WHERE IdFactura=@IdFactura AND IdProducto = @IdProducto"; await conn.ExecuteAsync(query, new { facturaProducto.IdFactura, facturaProducto.IdProducto, facturaProducto.ValorProducto, facturaProducto.CantidadProducto }, commandType : CommandType.Text); } return(true); }
public ActionResult Create([Bind(Include = "Id,IdCliente,IdProducto,Cantidad,Fecha,Monto")] FacturaProducto facturaProducto) { if (ModelState.IsValid) { facturaProducto.Fecha = DateTime.Now; RepositoryProducto repositoryProducto = new RepositoryProducto(); Producto prod = new Producto(); prod = repositoryProducto.GetById(facturaProducto.IdProducto); facturaProducto.Monto = prod.Precio * facturaProducto.Cantidad; db.FacturaProductos.Add(facturaProducto); db.SaveChanges(); log.Info("Creacion de factura producto"); return(RedirectToAction("Index")); } ViewBag.IdCliente = new SelectList(db.Clientes, "Id", "NombreCompleto", facturaProducto.IdCliente); ViewBag.IdProducto = new SelectList(db.Productos, "Id", "Nombre", facturaProducto.IdProducto); return(View(facturaProducto)); }
public static bool CrearFacturaProducto(FacturaProducto facturaProducto) { bool response = false; try { using (var dbContextScope = new DigitalWareEntities()) { dbContextScope.FacturaProducto.Add(facturaProducto); dbContextScope.SaveChanges(); response = true; } } catch (Exception ex) { throw ex; } return(response); }
public Task <FacturaProducto> Update(FacturaProducto v) { throw new NotImplementedException(); }