public IActionResult Index(Microsoft.AspNetCore.Http.FormCollection formCollection)
        {
            try
            {
                Models.Person person = new Models.Person()
                {
                    Name      = Request.Form["personname"].ToString(),
                    Address   = Request.Form["address"].ToString(),
                    ContactNo = Request.Form["contactno"].ToString(),
                    Picture   = string.Empty
                };

                PersonRepo.Add(person);
            }
            catch (Exception) { ViewBag.ClusterIPError = "Unable to add records. Please verify your connection."; }

            List <Models.Person> personCollection = PersonRepo.GetAll().ToList();

            return(View(personCollection));
        }
Пример #2
0
        public IActionResult Index(Microsoft.AspNetCore.Http.FormCollection formCollection)
        {
            try
            {
                BsonDocument doc = new BsonDocument();
                doc.Add(new BsonElement("Name", Request.Form["restname"].ToString()));
                doc.Add(new BsonElement("Address", Request.Form["address"].ToString()));
                doc.Add(new BsonElement("RestaurantId", Request.Form["restaurantId"].ToString()));
                doc.Add(new BsonElement("Cuisine", Request.Form["cuisine"].ToString()));

                if (MONGO_DATABASE == null)
                {
                    ViewBag.ClusterIPError = "MongoDB Cluster IP is not set."; return(null);
                }
                var collection = MONGO_DATABASE.GetCollection <BsonDocument>(COLLECTION_NAME);
                collection.InsertOne(doc);
            }
            catch (Exception ex) { ViewBag.ClusterIPError = "Unable to add records. Please verify your connection."; /*Logger.Error(ex, "Index");*/ }

            List <Restaurants> restCollection = ListRestaurants();

            return(View(restCollection));
        }