public ActionResult Create(SitiosModel collection) { sitiosCollection = _dbcontext.database.GetCollection <SitiosModel>("Sitios"); sitiosCollection.InsertOne(collection); Console.WriteLine("Insert"); return(RedirectToAction("Index")); }
public ActionResult Delete(string id, SitiosModel collection) { try { sitiosCollection = _dbcontext.database.GetCollection <SitiosModel>("Sitios"); sitiosCollection.DeleteOne(Builders <SitiosModel> .Filter.Eq("_id", ObjectId.Parse(id))); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(string id, SitiosModel collection) { try { sitiosCollection = _dbcontext.database.GetCollection <SitiosModel>("Sitios"); sitiosCollection.DeleteOne(Builders <SitiosModel> .Filter.Eq("_id", ObjectId.Parse(id))); Create(collection); var filter = Builders <SitiosModel> .Filter.Eq("_id", ObjectId.Parse(id)); var update = Builders <SitiosModel> .Update.Set("Nombre", collection.Nombre);//Se puede agregar mas haciendo un .Set("",) extra var result = sitiosCollection.UpdateOne(filter, update); return(RedirectToAction("Index")); } catch { return(View()); } }