Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why Update shows correct error message but not New
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Why Update shows correct error message but not New
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01623046
Message ID:
01623046
Vues:
50
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
Répondre
Fil
Voir

Click here to load this message in the networking platform