public ActionResult Create(Tip tip) { var user = db.Institutos.Where(u => u.Correo == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { db.Tips.Add(tip); db.SaveChanges(); if (tip.ContenidoFile != null) { var folder = "~/Content/ContenidoTips"; var file = string.Format("{0}{1}.jpg", tip.Titulo, user.InstitutoId); var response = FileHelper.UploadPhoto(tip.ContenidoFile, folder, file); if (response) { var pic = string.Format("{0}/{1}", folder, file); tip.Contenido = pic; db.Entry(tip).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CategoriaTipId = new SelectList(CombosHelper.GetCategoriaTips(), "CategoriaTipId", "Nombre", tip.CategoriaTipId); return(View(tip)); }
public ActionResult Create() { var user = db.Institutos.Where(u => u.Correo == User.Identity.Name).FirstOrDefault(); ViewBag.CategoriaTipId = new SelectList(CombosHelper.GetCategoriaTips(), "CategoriaTipId", "Nombre"); var tips = new Tip { InstitutoId = user.InstitutoId, }; return(View(tips)); }