public ActionResult Edit(int _id) { ViewBag.State = "Editar Recomendación"; using (FakebookContext Fk = new FakebookContext()) { //Creamos una instancia de un post para colocar nuesto elemnto editado Thread editThread = Fk.Threads.First(x => x.Id == _id); //creamos la instancia del nuevo modelo para alta de post ThreadCRU threadCRU = new ThreadCRU(Fk.Categories.ToList()); //compactamos las dos instancias para poder complementar vista y modelo threadCRU.Thread = editThread; return(View("Create", threadCRU)); } }
public ActionResult Create() { ViewBag.State = "Nueva Recomendación"; using (FakebookContext Fk = new FakebookContext()) { //Creamos una instancia de un nuevo post Thread newThread = new Thread(); //creamos la instancia del nuevo modelo para alta de post ThreadCRU AddThread = new ThreadCRU(Fk.Categories.ToList()); //compactamos las dos instancias para poder complementar vista y modelo AddThread.Thread = newThread; return(View(AddThread)); } }
public ActionResult AddOrEdit(ThreadCRU _threadCRUD) { Thread _thread = _threadCRUD.Thread; using (FakebookContext Fk = new FakebookContext()) { if (Fk.Threads.Any(x => x.Id == _thread.Id)) { Thread threadEdit = Fk.Threads.First(x => x.Id == _thread.Id); threadEdit.Title = _thread.Title; threadEdit.Description = _thread.Description; threadEdit.IdCategory = _thread.IdCategory; Fk.SaveChanges(); } else { Fk.Threads.Add(_thread); Fk.SaveChanges(); } return(RedirectToAction("Index")); } }