public bool AddNegocio_Producto(Negocio_Producto ent) { using (var context = getContext()) { context.Negocio_Producto.Add(ent); context.SaveChanges(); return(true); } }
public bool DeleteNegocio_Producto(Negocio_Producto ent) { using (var context = getContext()) { var obj = context.Negocio_Producto.Where(x => x.id_Negocio == ent.id_Negocio && x.id_Producto == ent.id_Producto).SingleOrDefault(); context.Negocio_Producto.Remove(obj); context.SaveChanges(); return(true); } }
public bool UpdateNegocio_Producto(Negocio_Producto ent) { using (var context = getContext()) { var obj = context.Negocio_Producto.Where(x => x.id_Negocio == ent.id_Negocio && x.id_Producto == ent.id_Producto).Include(x => x.Producto).SingleOrDefault(); obj.Precio = ent.Precio; context.SaveChanges(); return(true); } }
public ActionResult addProducto(Negocio_Producto ent) { if (!this.currentUser()) { return(RedirectToAction("Ingresar", "Login")); } try { if (ModelState.IsValid) { Producto obj = dal.GetProducto(ent.Producto.Nombre); if (obj == null) { obj = dal.AddProducto(ent.Producto.Nombre); } var pastObj = dal.GetNegocio_Producto(ent.id_Negocio, obj.id_Producto); if (ent.id_Producto == 0 && pastObj == null) { ent.id_Producto = obj.id_Producto; ent.Producto = null; dal.AddNegocio_Producto(ent); } else { if (ent.id_Producto != obj.id_Producto && pastObj != null) { } else { //Eliminar registro pasado☺ dal.DeleteNegocio_Producto(ent); //Agregar nuevo registro ent.id_Producto = obj.id_Producto; ent.Producto = null; dal.AddNegocio_Producto(ent); } } } return(RedirectToAction("Productos", new { id_Negocio = ent.id_Negocio })); } catch (Exception ex) { throw ex; } }
public ActionResult Producto(int id_Negocio, int id) { if (!this.currentUser()) { return(RedirectToAction("Ingresar", "Login")); } try { Negocio_Producto ent = new Negocio_Producto(); if (id_Negocio > 0 && id > 0) { ent = dal.GetNegocio_Producto(id_Negocio, id); return(View(ent)); } ent.id_Negocio = id_Negocio; ent.Producto = new Entities.Producto(); return(View(ent)); } catch (Exception ex) { throw ex; } }