public ActionResult Create(AgregarProductoViewModels productoVM) { try { productos producto = new productos { nombre = productoVM.Nombre, precio = productoVM.Precio, descripcion = productoVM.Descripcion, modelo = productoVM.Modelo, cantidad = productoVM.cantidad, id_marca = productoVM.id_marca, id_distribuidor = productoVM.id_distribuidor, id_categoria = productoVM.id_categoria, id_coleccion = productoVM.id_coleccion, id_estado = 2 }; unidad_productos.genericDAL.Add(producto); unidad_productos.Complete(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Edit(DistribuidoresViewModel distribuidorVM) { try { if (ModelState.IsValid) { distribuidor distribuidor = new distribuidor { id_distribuidor = distribuidorVM.id_distribuidor, nombre = distribuidorVM.nombre, email = distribuidorVM.email, direccion = distribuidorVM.direccion, id_estado = 2 }; using (UnidadDeTrabajo <distribuidor> unidad_distribuidor = new UnidadDeTrabajo <distribuidor>(new BDContext())) { unidad_distribuidor.genericDAL.Update(distribuidor); unidad_distribuidor.Complete(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } // devolver que todo bien } // modelo no valido, devolver error 500 return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } catch (DataException /* dex */) { // devolver error 500 return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Create(TipoDeducionViewModel tipoDeducionViewModel) { string mensaje = ""; try { TIPO_DEDUCCIONES parametro = this.Convertir(tipoDeducionViewModel); mensaje = "Registro agregado satisfactoriamente"; using (UnidadDeTrabajo <TIPO_DEDUCCIONES> unidad = new UnidadDeTrabajo <TIPO_DEDUCCIONES>(new BDContext())) { unidad.genericDAL.Add(parametro); if (!unidad.Complete()) { TempData["mensaje"] = "El registro ya existe"; return(RedirectToAction("Create")); } } } catch (Exception ex) { mensaje = ex.ToString(); } TempData["mensaje"] = mensaje; return(RedirectToAction("Index")); }
public ActionResult Edit(C_Animales animales, HttpPostedFileBase UploadImage) { if (UploadImage != null) { if (UploadImage.ContentType == "image/jpg" || UploadImage.ContentType == "image/png" || UploadImage.ContentType == "image/bmp" || UploadImage.ContentType == "gif" || UploadImage.ContentType == "image/jpeg") { UploadImage.SaveAs(Server.MapPath("/") + "/Cargas/" + UploadImage.FileName); animales.ImagenURL = UploadImage.FileName; } else { return(View()); } } else { return(View()); } using (UnidadDeTrabajo <C_Animales> unidad = new UnidadDeTrabajo <C_Animales>(new BDContext())) { unidad.genericDAL.Update(animales); unidad.Complete(); } return(RedirectToAction("Index")); }
public ActionResult Create(DistribuidoresViewModel distribuidorVM) { try { // TODO: Add insert logic here distribuidor distribuidor = new distribuidor { id_distribuidor = distribuidorVM.id_distribuidor, nombre = distribuidorVM.nombre, email = distribuidorVM.email, direccion = distribuidorVM.direccion, id_estado = 2 }; if ((distribuidor.nombre != null) && (distribuidor.email != null)) { using (UnidadDeTrabajo <distribuidor> unidad = new UnidadDeTrabajo <distribuidor>(new BDContext())) { unidad.genericDAL.Add(distribuidor); unidad.Complete(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } else { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } catch { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Create(CategoriasViewModel categoriaVM) { try { // TODO: Add insert logic here categorias categoria = new categorias { nombre = categoriaVM.nombre, descripcion = categoriaVM.descripcion, id_estado = 2 }; if (categoria.nombre != null) { using (UnidadDeTrabajo <categorias> unidad = new UnidadDeTrabajo <categorias>(new BDContext())) { unidad.genericDAL.Add(categoria); unidad.Complete(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } else { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } } catch { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public void actualizarProducto() { double result; productos productos; using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext())) { productos = new productos { productoId = 1, nombre = "Samsung galaxy 222", precio = 1000, descripcion = "Computadoras,tablets,celulares", modelo = "122SS11", id_categoria = 1, id_marca = 1, id_coleccion = null, id_bodega = null, id_distribuidor = null }; unidad.genericDAL.Update(productos); unidad.Complete(); } result = (double)productos.precio; Assert.AreEqual(1000, result); }
public void eliminarProducto() { int resultadoAnterior; int resultado; productos productos; using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext())) { resultadoAnterior = unidad.genericDAL.GetAll().ToList().Count; } using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext())) { productos = unidad.genericDAL.Get(2); } using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext())) { unidad.genericDAL.Remove(productos); unidad.Complete(); } using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext())) { resultado = unidad.genericDAL.GetAll().ToList().Count; } Assert.AreEqual(resultadoAnterior - 1, resultado); }
public ActionResult Create(ComidasViewModel comidasViewModel) { string mensaje = ""; try { mensaje = "Agregado con exito"; Producto produc = new Producto() { nombre = comidasViewModel.nombre, precio = comidasViewModel.precio, cantidad = comidasViewModel.cantidad, imagen_comida = comidasViewModel.imagen_comida }; using (UnidadDeTrabajo <Producto> unidad = new UnidadDeTrabajo <Producto>(new BDContext())) { produc.id_comida = unidad.genericDAL.GetAll().Count() + 1; unidad.genericDAL.Add(produc); unidad.Complete(); } } catch (Exception ex) { mensaje = ex.ToString(); } TempData["mensaje"] = mensaje; return(RedirectToAction("Index")); }
public ActionResult Edit(DEDUCCIONES_EMPLEADOS duducionEmpleado) { string mensaje = ""; try { mensaje = "Registro modificado satisfactoriamente"; using (UnidadDeTrabajo <DEDUCCIONES_EMPLEADOS> unidad = new UnidadDeTrabajo <DEDUCCIONES_EMPLEADOS>(new BDContext())) { using (var context = new BDContext()) { var result = context .Database .SqlQuery <int>("SELECT e.idEmpleado as idEmpleado FROM PERSONAS p, EMPLEADOS e WHERE p.idPersona = e.idPersona and p.idPersona = @pIdEMpleado ", new SqlParameter("@pIdEMpleado", duducionEmpleado.idEmpleado)).FirstOrDefault(); duducionEmpleado.idEmpleado = result; } unidad.genericDAL.Update(duducionEmpleado); unidad.Complete(); } } catch (Exception ex) { mensaje = ex.ToString(); } TempData["mensaje"] = mensaje; return(RedirectToAction("Index")); }
public ActionResult Edit(ComidasViewModel comidasViewModel) { string mensaje = ""; try { mensaje = "Modificado con exito"; Producto producto = new Producto() { id_comida = comidasViewModel.id_comida, nombre = comidasViewModel.nombre, precio = comidasViewModel.precio, cantidad = comidasViewModel.cantidad, imagen_comida = comidasViewModel.imagen_comida }; using (UnidadDeTrabajo <Producto> unidad = new UnidadDeTrabajo <Producto>(new BDContext())) { unidad.genericDAL.Update(producto); unidad.Complete(); } } catch (Exception ex) { mensaje = ex.ToString(); } TempData["mensaje"] = mensaje; return(RedirectToAction("Index")); }
public ActionResult Create(EMPLEADOS empleado) { string mensaje = ""; try { mensaje = "Registro agregado satisfactoriamente"; using (UnidadDeTrabajo <EMPLEADOS> unidad = new UnidadDeTrabajo <EMPLEADOS>(new BDContext())) { unidad.genericDAL.Add(empleado); if (!unidad.Complete()) { TempData["mensaje"] = "El registro ya existe"; return(RedirectToAction("Create")); } } } catch (Exception ex) { mensaje = ex.ToString(); } TempData["mensaje"] = mensaje; return(RedirectToAction("Index")); }
public void agregarImagenProducto() { imagen_producto imagen; int resultadoAnterior; int resultado; using (UnidadDeTrabajo <imagen_producto> unidad = new UnidadDeTrabajo <imagen_producto>(new BDContext())) { resultadoAnterior = unidad.genericDAL.GetAll().ToList().Count; } using (UnidadDeTrabajo <imagen_producto> unidad = new UnidadDeTrabajo <imagen_producto>(new BDContext())) { unidad.genericDAL.Add(imagen = new imagen_producto() { IMAGEN = "img/imagen2.jpg", productoId = 2 }); unidad.Complete(); } using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext())) { resultado = unidad.genericDAL.GetAll().ToList().Count; } Assert.AreEqual(resultadoAnterior + 1, resultado); }
public ActionResult Edit(CategoriasViewModel categoriasViewModel) { try { if (ModelState.IsValid) { using (UnidadDeTrabajo <categorias> unidad = new UnidadDeTrabajo <categorias>(new BDContext())) { categorias categoria = new categorias { id_categoria = categoriasViewModel.id_categoria, nombre = categoriasViewModel.nombre, descripcion = categoriasViewModel.descripcion, id_estado = 2 }; unidad.genericDAL.Update(categoria); unidad.Complete(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } catch { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Edit(MarcasViewModel marcasViewModel) { try { if (ModelState.IsValid) { using (UnidadDeTrabajo <marcas> unidad = new UnidadDeTrabajo <marcas>(new BDContext())) { marcas marca = new marcas { id_marca = marcasViewModel.id_marca, nombre = marcasViewModel.nombre, descripcion = marcasViewModel.descripcion }; unidad.genericDAL.Update(marca); unidad.Complete(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } catch { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Delete(int id) { try { // revisar si el URL contiene un ID, si no entonces devolver 404 if (id == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } promociones promocion; using (UnidadDeTrabajo <promociones> unidad = new UnidadDeTrabajo <promociones>(new BDContext())) { promocion = unidad.genericDAL.Get(id); promocion.id_estado = 1; } using (UnidadDeTrabajo <promociones> unidad = new UnidadDeTrabajo <promociones>(new BDContext())) { unidad.genericDAL.Update(promocion); unidad.Complete(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public ActionResult Create(PromocionesViewModel promocionVM) { try { // TODO: Add insert logic here promociones promocion = new promociones { nombre = promocionVM.nombre, descripcion = promocionVM.descripcion, valor = promocionVM.valor, id_estado = 2 }; using (UnidadDeTrabajo <promociones> unidad = new UnidadDeTrabajo <promociones>(new BDContext())) { unidad.genericDAL.Add(promocion); unidad.Complete(); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Edit(PromocionesViewModel promocionesViewModel) { try { if (ModelState.IsValid) { promociones promocion = new promociones { promocionId = promocionesViewModel.promocionId, nombre = promocionesViewModel.nombre, descripcion = promocionesViewModel.descripcion, valor = promocionesViewModel.valor, id_estado = 2 }; using (UnidadDeTrabajo <promociones> unidad = new UnidadDeTrabajo <promociones>(new BDContext())) { unidad.genericDAL.Update(promocion); unidad.Complete(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } } return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } catch (DataException /* dex */) { // devolver error 500 return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Create(ParametroViewModel parametroViewModel) { string mensaje = ""; try { PARAMETROS parametro = this.Convertir(parametroViewModel); mensaje = "Registro agregado satisfactoriamente"; using (UnidadDeTrabajo <PARAMETROS> unidad = new UnidadDeTrabajo <PARAMETROS>(new BDContext())) { unidad.genericDAL.Add(parametro); if (!unidad.Complete()) { TempData["mensaje"] = "No puede agregar un registro sin datos"; return(RedirectToAction("Create")); } } } catch (Exception ex) { mensaje = ex.ToString(); } TempData["mensaje"] = mensaje; return(RedirectToAction("Index")); }
public ActionResult Create(UserViewModel userViewModel) { string mensaje = ""; try { mensaje = "Agregado con exito"; User user = new User() { UserId = userViewModel.UserViewModelId, nombre = userViewModel.nombre, apellidos = userViewModel.apellidos, Password = userViewModel.Password, mail = userViewModel.mail, UserName = userViewModel.UserName, phone = userViewModel.phone }; using (UnidadDeTrabajo <User> unidad = new UnidadDeTrabajo <User>(new BDContext())) { unidad.genericDAL.Add(user); unidad.Complete(); } } catch (Exception ex) { mensaje = ex.ToString(); } TempData["mensaje"] = mensaje; return(RedirectToAction("Index")); }
public ActionResult Edit(LicoresViewModel licorViewModel) { if (licorViewModel.Foto != null) { byte[] img = null; using (var binary = new System.IO.BinaryReader(licorViewModel.Foto.InputStream)) { img = binary.ReadBytes(licorViewModel.Foto.ContentLength); } string archivoBase64 = System.Convert.ToBase64String(img); licorViewModel.Foto_Licor = archivoBase64; using (UnidadDeTrabajo <Licores> unidad = new UnidadDeTrabajo <Licores>(new BDContext())) { unidad.genericDAL.Update(this.Convertir(licorViewModel)); unidad.Complete(); } } else { using (UnidadDeTrabajo <Licores> unidad = new UnidadDeTrabajo <Licores>(new BDContext())) { unidad.genericDAL.Update(this.Convertir(licorViewModel)); unidad.Complete(); } } return(RedirectToAction("Index")); }
public ActionResult Agregar(DetallesProductoViewModels productoVM) { BDContext context = new BDContext(); try { // obtener el id del usuario que esta logueado var userID = User.Identity.GetUserId(); // obtener el usuario con ese id de base de datos var usuario_BD = context.usuarios.Where(u => u.Usuario_ID.Equals(userID)).Single(); // obtener productos del carrito del usuario List <sp_obtenerProductosUsuarioCarrito_Result> lista_productos_cliente = context.sp_obtenerProductosUsuarioCarrito(usuario_BD.userId).ToList(); // verificar si el usuario ya tiene ese producto en el carrito foreach (var producto in lista_productos_cliente) { if (producto.productoId == productoVM.Id_Producto) { // usuario ya tiene ese producto en el carrito, preguntar si desea modificar return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } } // crear el producto que se va a agregar al carrito carrito producto_carrito = new carrito { productoId = productoVM.Id_Producto, userId = usuario_BD.userId, cantidad_producto = (int)productoVM.cantidad, fecha_agregado = DateTime.UtcNow, fecha_modificado = DateTime.UtcNow }; unidad_carrito.genericDAL.Add(producto_carrito); unidad_carrito.Complete(); // devolver http 200 return(new HttpStatusCodeResult(HttpStatusCode.OK)); } catch (Exception) { // error, devolver http 500 return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Register(UsuarioViewModel usuarioViewModel) { usuarioViewModel.usuario = Request["usuario"]; usuarioViewModel.contrasenia = Request["contrasenia"]; PERSONAS p; List <PERSONAS> listP; string id; using (UnidadDeTrabajo <PERSONAS> Unidad = new UnidadDeTrabajo <PERSONAS>(new BDContext())) { listP = Unidad.genericDAL.GetAll().ToList(); id = this.RandomString(12); foreach (var item in listP) { while (id == item.numeroIdentificacion) { id = this.RandomString(12); //genero una cedula unica } } p = new PERSONAS { correoElectronico = "generico", estado = 1, genero = 1, nacionalidad = 1, numeroIdentificacion = id, nombrePersona = "generico", segundoApellido = "generico", telefono = "generico", primerApellido = "generico", }; Unidad.genericDAL.Add(p);//creo una persona Unidad.Complete(); } int ide = 0; using (UnidadDeTrabajo <PERSONAS> Unidad = new UnidadDeTrabajo <PERSONAS>(new BDContext())) { listP = Unidad.genericDAL.GetAll().ToList(); foreach (var item in listP) { if (item.numeroIdentificacion == id) { ide = item.idPersona; //obtengo id de la persona } } Unidad.Complete(); } using (UnidadDeTrabajo <USUARIOS> Unidad = new UnidadDeTrabajo <USUARIOS>(new BDContext())) { usuarioViewModel.idPersona = ide; Unidad.genericDAL.Add(this.Convertir(usuarioViewModel)); Unidad.Complete(); } return(RedirectToAction("Index", "Login")); }
public void TestDelete() { using (UnidadDeTrabajo <PARAMETROS> Unidad = new UnidadDeTrabajo <PARAMETROS>(new BDContext())) { PARAMETROS parametro = Unidad.genericDAL.Get(9); Unidad.genericDAL.Remove(parametro); Assert.AreEqual(true, Unidad.Complete()); } }
public JsonResult Compra_Final(ProductoViewModel producto) { IUserDAL userDAL = new UserDALImpl(); CompraViewModel lista = Session["Entradas"] as CompraViewModel; User userViewModel = Session["Usuario_Compra"] as User; Session["Orden_Comida"] = producto; producto = Session["Orden_Comida"] as ProductoViewModel; int id_sala = Convert.ToInt32(lista.sala); Asiento asiento = new Asiento(); Reserva reserva = new Reserva(); User user_temp; User user = new User() { nombre = userViewModel.nombre, apellidos = userViewModel.apellidos, Password = userViewModel.Password, mail = userViewModel.mail, UserName = userViewModel.nombre, phone = userViewModel.phone, card = userViewModel.card }; using (UnidadDeTrabajo <User> unidad = new UnidadDeTrabajo <User>(new BDContext())) { unidad.genericDAL.Add(user); unidad.Complete(); user_temp = userDAL.getUser(user.nombre); reserva.id_cliente = user_temp.UserId; } foreach (var item in lista.numero_asiento) { asiento.id_sala = id_sala; asiento.numero_asiento = item; asiento.estado = 1; using (UnidadDeTrabajo <Asiento> unidad = new UnidadDeTrabajo <Asiento>(new BDContext())) { asiento.id_asiento = unidad.genericDAL.GetAll().Count() + 1; unidad.genericDAL.Add(asiento); unidad.Complete(); reserva.id_asiento = unidad.genericDAL.GetAll().Count(); } using (UnidadDeTrabajo <Reserva> unidad = new UnidadDeTrabajo <Reserva>(new BDContext())) { reserva.id_reserva = unidad.genericDAL.GetAll().Count() + 1; unidad.genericDAL.Add(reserva); unidad.Complete(); } } return(Json("Exito")); }
public ActionResult Edit(ServicioViewModel servicioViewModel) { using (UnidadDeTrabajo <Servicio> unidad = new UnidadDeTrabajo <Servicio>(new BDContext())) { unidad.genericDAL.Update(this.Convertir(servicioViewModel)); unidad.Complete(); } return(RedirectToAction("Index")); }
public ActionResult Delete(ReservaViewModel reservaViewModel) { using (UnidadDeTrabajo <Reservas> unidad = new UnidadDeTrabajo <Reservas>(new BDContext())) { unidad.genericDAL.Remove(this.Convertir(reservaViewModel)); unidad.Complete(); } return(RedirectToAction("Index")); }
public ActionResult Edit(Reservas reserva) { using (UnidadDeTrabajo <Reservas> unidad = new UnidadDeTrabajo <Reservas>(new BDContext())) { unidad.genericDAL.Update(reserva); unidad.Complete(); } return(RedirectToAction("Index")); }
public ActionResult Edit(HistorialViewModel historialViewModel) { using (UnidadDeTrabajo <Historial> unidad = new UnidadDeTrabajo <Historial>(new BDContext())) { unidad.genericDAL.Update(this.Convertir(historialViewModel)); unidad.Complete(); } return(RedirectToAction("Index")); }
public ActionResult Delete(USUARIOS usuario) { using (UnidadDeTrabajo <USUARIOS> unidad = new UnidadDeTrabajo <USUARIOS>(new BDContext())) { unidad.genericDAL.Remove(usuario); unidad.Complete(); } TempData["mensaje"] = "Registro eliminado satisfactoriamente"; return(RedirectToAction("Index")); }