Exemple #1
0
 public IActionResult Post([FromBody] IdorViewModel idor)
 {
     if (ModelState.IsValid)
     {
         string    username = _httpContextAccessor.HttpContext.Request.Cookies.FirstOrDefault(x => x.Key == "User").Value.ToString();
         IdorModel value    = new IdorModel {
             IdorValue = idor.IdorValue, Owner = username
         };
         _myContext.Idor.Add(value);
         _myContext.SaveChanges();
         return(Ok("New value was stored succesfull!"));
     }
     else
     {
         return(BadRequest("Storing the item has failed!"));
     }
 }
Exemple #2
0
 public IActionResult Put(int id, [FromBody] IdorViewModel value)
 {
     if (ModelState.IsValid)
     {
         var result = _myContext.Idor.SingleOrDefault(x => x.IdorId == id);
         if (result != null)
         {
             result.IdorValue = value.IdorValue;
             _myContext.Update(result);
             _myContext.SaveChanges();
         }
         return(Ok("New value was updated succesfull!"));
     }
     else
     {
         return(BadRequest("Update of the item has failed!"));
     }
 }