Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why Update shows correct error message but not New
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Why Update shows correct error message but not New
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01623046
Message ID:
01623046
Views:
51
UPDATE. We got it to work by using error method of the promise.


Hi everybody,

I have the following code:
 [Route("")]
[HttpPost]
 public IHttpActionResult CreateMax4Sale(EditMax4SaleViewModel max4saleViewModel)
        {
            int conflicts = ChangeMax4Sale(max4saleViewModel, "Add");
            if (conflicts > 0)
            {
                var response = (conflicts == 1) ? Messages.existingConflict : String.Format(Messages.xExistingConflicts, conflicts);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(response),
                    ReasonPhrase = response
                });
            }

            return Ok(max4saleViewModel);
        }

        [Route("")]
        [HttpPut]
        public IHttpActionResult UpdateMax4Sale(EditMax4SaleViewModel max4saleViewModel)
        {
            int conflicts = ChangeMax4Sale(max4saleViewModel, "Update");
            if (conflicts > 0)
            {
                var response = (conflicts == 1) ? Messages.existingConflict : String.Format(Messages.xExistingConflicts, conflicts);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent(response),
                    ReasonPhrase = response
                });
            }

            return Ok(max4saleViewModel);
        }
Now, the Update method shows correct error message (the one I produced) when there are conflicts. But the New method displays our generic error message instead. The difference between the two that one uses HttpPut and the other HttpPost attribute.

How can I make the New method to behave the same as Update?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Reply
Map
View

Click here to load this message in the networking platform