Example #1
0
 // POST api/Tornir
 public HttpResponseMessage Post([FromBody] Tornir value)
 {
     using (TornirDBEntities entity = new TornirDBEntities())
     {
         entity.Tornirs.Add(value);
         entity.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + value.ID.ToString())));
     }
 }
Example #2
0
        // GET api/Tornir/5

        public HttpResponseMessage Get(int id)
        {
            using (TornirDBEntities entity = new TornirDBEntities())
            {
                Tornir tornir = entity.Tornirs.FirstOrDefault(x => x.ID == id);
                if (tornir != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, tornir));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
        }
Example #3
0
 // DELETE api/Tornir/5
 public HttpResponseMessage Delete(int id)
 {
     using (TornirDBEntities entity = new TornirDBEntities())
     {
         Tornir tornirToDeleate = entity.Tornirs.FirstOrDefault(x => x.ID == id);
         if (tornirToDeleate != null)
         {
             entity.Tornirs.Remove(tornirToDeleate);
             entity.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"tornir with id:{id} delated")));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"tornir with id:{id} was not found")));
         }
     }
 }
Example #4
0
 // PUT api/Tornir/5
 public HttpResponseMessage Put(int id, [FromBody] Tornir value)
 {
     using (TornirDBEntities entity = new TornirDBEntities())
     {
         Tornir tornirToUpdate = entity.Tornirs.FirstOrDefault(x => x.ID == id);
         if (tornirToUpdate != null)
         {
             tornirToUpdate.Game_Name = value.Game_Name;
             tornirToUpdate.Player1   = value.Player1;
             tornirToUpdate.Player2   = value.Player2;
             tornirToUpdate.Who_Won   = value.Who_Won;
             entity.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"tornir with id: {id} updeted")));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"tornir with id:{id} was not found")));
         }
     }
 }