Esempio n. 1
0
 public ActionResult Create(SitiosModel collection)
 {
     sitiosCollection = _dbcontext.database.GetCollection <SitiosModel>("Sitios");
     sitiosCollection.InsertOne(collection);
     Console.WriteLine("Insert");
     return(RedirectToAction("Index"));
 }
Esempio n. 2
0
        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());
            }
        }
Esempio n. 3
0
        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());
            }
        }