コード例 #1
0
 /// <summary>
 /// Post API/Vote
 /// </summary>
 /// <param name="E">Vote à insérer</param>
 public IHttpActionResult Post(VoteModel Vote)
 {
     if ((new[] { "Admin", "User" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase))
     {
         if (Vote == null || Vote.Strategy.Id == 0 || Vote.User.Id == 0)
         {
             return(BadRequest());
         }
         else
         {
             repo.Create(Vote.ToEntity());
             return(Ok());
         }
     }
     else
     {
         return(Unauthorized());
     }
 }
コード例 #2
0
 public IActionResult Put(int id, [FromBody] VoteModel Vote)
 {
     if ((new[] { "Admin", "User" }).Contains(ValidateTokenAndRole.ValidateAndGetRole(Request), StringComparer.OrdinalIgnoreCase))
     {
         if (repo.GetOne(id) == null)
         {
             return(NotFound());
         }
         else if (Vote == null || Vote.Strategy.Id == 0 || Vote.User.Id == 0)
         {
             return(BadRequest());
         }
         else
         {
             repo.Update(id, Vote.ToEntity());
             return(Ok());
         }
     }
     else
     {
         return(Unauthorized());
     }
 }