Example #1
0
        // Only creates the field if there's no other field with the same name
        public async Task <bool> CreateField(CreateFieldVM viewModel)
        {
            var Json = await getWebApi("Field/createField");

            var result = JsonConvert.DeserializeObject <bool>(Json);

            return(result);
        }
        public async Task <IActionResult> CreateField(CreateFieldVM viewModel)
        {
            var result = await dataManager.CreateField(viewModel);

            if (result)
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ViewData["FieldIsInvalid"] = "1";
                return(View(viewModel));
            }
        }
Example #3
0
        // Only creates the field if there's no other field with the same name
        public bool CreateField(CreateFieldVM viewModel)
        {
            SqlConnection myConnection = new SqlConnection();

            myConnection.ConnectionString = connectionString;

            try
            {
                myConnection.Open();
                double     dub   = 0.0;
                int        votes = 0;
                SqlCommand cmd   = new SqlCommand();
                cmd.Connection  = myConnection;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Create_Field";
                cmd.Parameters.Add(new SqlParameter("@Capacity", viewModel.Capacity));
                cmd.Parameters.Add(new SqlParameter("@Condition", dub));
                cmd.Parameters.Add(new SqlParameter("@Coordinates", string.IsNullOrWhiteSpace(viewModel.Coordinates) ? "" : viewModel.Coordinates));
                cmd.Parameters.Add(new SqlParameter("@Description", string.IsNullOrWhiteSpace(viewModel.Description) ? "" : viewModel.Description));
                cmd.Parameters.Add(new SqlParameter("@Lighting", viewModel.Lighting));
                cmd.Parameters.Add(new SqlParameter("@Name", viewModel.Name));
                cmd.Parameters.Add(new SqlParameter("@Turf", viewModel.Turf));
                cmd.Parameters.Add(new SqlParameter("@Votes", votes));


                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                myConnection.Close();
            }
            return(true);
        }