Need good guidance to MVC 5 Web API route conifguration

Hi,

I'm writing my first MVC5 API in Visual Studio 2017 and C#.  I'm not doing this in .net Core because I need to use CSOM, SharePont online Client object to update SharePoint online Document Library column data and that is no yet supported in .net Cored.

I seem to understand more about MVC routing in regular Controller and Actions but I'm very lost in the API configuration.  I used the MVC WEB API template and created the basic Get, ..post...Put..Delete....   public method under my API.

The first one method I want to do is to perform an update on a column data on the SPO Document Library's column.  I supposed that would be the Put method?  Or can I rename that method?  I coded my method as below and when I put in http it just defaults to the first Get method with no parameter.  What should I add in the WebApiConfig.cs for this to work.  I'm passing in a string value like "True" or "False", the method then assign this string to the column data of the document library.  The problem is it's not even getting hit.

I read a couple of article online which kept sending me to another link, another....  I'm just very confused and still don't know how to setup the WebApiConfig.cs

Before the declaration of my public API class, I have

[RoutePrefix("api/SetFlags")]

        // PUT api/<controlle
        // PUT api/<controller>/False
        [Route("{string:flagValue}")]
        public void Put(string flagValue)
        {
            List pnpList = pnpContext.Web.Lists.GetByTitle("GetAlarmsListing");
            CamlQuery query = CamlQuery.CreateAllItemsQuery();
            ListItemCollection allPnpDocs = pnpList.GetItems(query);
            pnpContext.Load(allPnpDocs);
            pnpContext.ExecuteQuery();

            foreach (ListItem pnpDoc in allPnpDocs)

          {
                pnpDoc["90DaysAlarmSent"] = flagValue;
                pnpDoc["Title"] = flagValue;//30DaysAlarmSent
                pnpDoc.Update();
            }

            pnpContext.ExecuteQuery();
        }

Open in new window


Thank you.
lapuccaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AZZA-KHAMEESCommented:
Change the method signature like this:

public void Put(string id)
{
    // your rest of the coding here..
}

It's because your Web API Configuration will expect a default parameter with a name "id".

Hope this would help!

Good Luck,
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lapuccaAuthor Commented:
Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.