public ActionResult Create([Bind(Include = "prd_id,cat_id,prm_id,prd_nom,prd_img,prd_tal,prd_crt,prd_cnt,prd_prc,prd_dateOfCreated")] Producto producto) { HttpPostedFileBase fileBase = Request.Files[0]; string path = SubirImagen(fileBase); if (path != "") { producto.prd_img = path; } else { producto.prd_img = "default"; } if (ModelState.IsValid) { ProductoBLL.Create(producto); return(RedirectToAction("Index")); } //ViewBag.Menssage = file.FileName; ViewBag.cat_id = new SelectList(CategoriaBLL.List(), "cat_id", "cat_nom", producto.cat_id); ViewBag.prm_id = new SelectList(PromocionBLL.List(), "prm_id", "prm_nom", producto.prm_id); ViewBag.file = fileBase; //producto.prd_img = SubirImagen(file); return(View(producto)); }
public ActionResult Edit([Bind(Include = "prm_id,prm_nom,prm_tip,prm_can,prm_por")] Promocion promocion) { if (ModelState.IsValid) { PromocionBLL.Update(promocion); return(RedirectToAction("Index")); } return(View(promocion)); }
public IHttpActionResult Delete(int id) { try { PromocionBLL.Delete(id); return(Ok("Promoción eliminada correctamente")); } catch (Exception ex) { return(Content(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult Get() { try { List <Promocion> todos = PromocionBLL.List(); return(Content(HttpStatusCode.OK, todos)); } catch (Exception) { return(BadRequest()); } }
public IHttpActionResult Get(int id) { try { Promocion Promocion = PromocionBLL.Get(id); return(Content(HttpStatusCode.OK, Promocion)); } catch (Exception) { return(NotFound()); } }
public IHttpActionResult Post(Promocion promocion) { try { PromocionBLL.Create(promocion); return(Content(HttpStatusCode.Created, "Promoción creada correctamente")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Put(Promocion promocion) { try { PromocionBLL.Updates(promocion); return(Content(HttpStatusCode.Accepted, "Promoción actualizada correctamente")); } catch (Exception ex) { return(BadRequest(ex.Message + promocion.ToString())); } }
// GET: Promociones/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Promocion promocion = PromocionBLL.Get(id); if (promocion == null) { return(HttpNotFound()); } return(View(promocion)); }
// GET: Productos/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Producto producto = ProductoBLL.Get(id); if (producto == null) { return(HttpNotFound()); } ViewBag.cat_id = new SelectList(CategoriaBLL.List(), "cat_id", "cat_nom", producto.cat_id); ViewBag.prm_id = new SelectList(PromocionBLL.List(), "prm_id", "prm_nom", producto.prm_id); return(View(producto)); }
public ActionResult Edit([Bind(Include = "prd_id,cat_id,prm_id,prd_nom,prd_img,prd_tal,prd_crt,prd_cnt,prd_prc,prd_dateOfCreated")] Producto producto) { if (Request.Files[0] != null && Request.Files[0].ContentLength > 0) { EliminarArchivo(producto.prd_img); producto.prd_img = SubirImagen(Request.Files[0]); } else { Producto prd = ProductoBLL.Get(producto.prd_id); producto.prd_img = prd.prd_img; } if (ModelState.IsValid) { ProductoBLL.Update(producto); return(RedirectToAction("Index")); } ViewBag.cat_id = new SelectList(CategoriaBLL.List(), "cat_id", "cat_nom", producto.cat_id); ViewBag.prm_id = new SelectList(PromocionBLL.List(), "prm_id", "prm_nom", producto.prm_id); return(View(producto)); }
public ActionResult UploadImages(string titulo, string mensaje, HttpPostedFileBase[] uploadImages) { ApplicationDbContext userscontext = new ApplicationDbContext(); var userStore = new UserStore <ApplicationUser>(userscontext); var userManager = new UserManager <ApplicationUser>(userStore); if (User.Identity.IsAuthenticated) { if (userManager.IsInRole(User.Identity.GetUserId(), "Admin")) { if (uploadImages.Count() == 0) { TempData["msg"] = "<script>alert('Debe añadir una imagen');</script>"; return(RedirectToAction("Promocion")); } foreach (var image in uploadImages) { if (image.ContentLength > 0) { byte[] imageData = null; using (var binaryReader = new BinaryReader(image.InputStream)) { imageData = binaryReader.ReadBytes(image.ContentLength); } PromocionBLL p = new PromocionBLL(); p.PostPromocion(imageData, titulo, mensaje); TempData["msg"] = "<script>alert('Datos Guardados');</script>"; } } return(RedirectToAction("Promocion")); } } return(RedirectToAction("Login", "Account")); }
// GET: Productos/Create public ActionResult Create() { ViewBag.cat_id = new SelectList(CategoriaBLL.List(), "cat_id", "cat_nom"); ViewBag.prm_id = new SelectList(PromocionBLL.List(), "prm_id", "prm_nom"); return(View()); }
// GET: Promociones public ActionResult Index() { return(View(PromocionBLL.List())); }
public ActionResult DeleteConfirmed(int id) { PromocionBLL.Delete(id); return(RedirectToAction("Index")); }
public List <PromocionDto> GetPromociones() { PromocionBLL p = new PromocionBLL(); return(p.GetPromiciones()); }