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