Exemplo n.º 1
0
        public IActionResult Index(Microsoft.AspNet.Http.Internal.FormCollection formCollection)
        {
            try
            {
                DataTable datatable = new DataTable();
                using (SqlConnection sqlConnection = new SqlConnection(ConnectionSetting.CONNECTION_STRING))
                {
                    string query = string.Format("Insert into {0}(Name,Address,Contactno,Picture) Values ('{1}','{2}','{3}','{4}')", TABLE_NAME, Request.Form["personname"].ToString(), Request.Form["address"].ToString(), Request.Form["contactno"].ToString(), string.Empty);
                    using (SqlCommand command = new SqlCommand(query, sqlConnection))
                    {
                        SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
                        sqlConnection.Open();
                        dataAdapter.Fill(datatable);
                        sqlConnection.Close();
                    }
                }
            }
            catch (Exception ex) { ViewBag.ClusterIPError = "Unable to add records. Please verify your connection."; Logger.Error(ex, "Index"); }


            string        error            = string.Empty;
            List <Person> personCollection = this.ListPersons(out error);

            if (!string.IsNullOrEmpty(error))
            {
                ViewBag.ClusterIPError = error;
            }
            return(View(personCollection));
        }
        public IActionResult Index(Microsoft.AspNet.Http.Internal.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()));

                var collection = MONGO_DATABASE.GetCollection <BsonDocument>(COLLECTION_NAME);
                collection.InsertOne(doc);
            }
            catch (Exception ex) { Logger.Error(ex, "Index"); }

            List <Restaurants> restCollection = ListRestaurants();

            return(View(restCollection));
        }
Exemplo n.º 3
0
        public IActionResult Index(Microsoft.AspNet.Http.Internal.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));
        }