예제 #1
0
        public IHttpActionResult Post(TodoModel value)
        {
            if (value == null)
            {
                return(BadRequest("Product cannot be null"));
            }
            using (TodoEntities1 entities = new TodoEntities1())
            {
                TodoList a = new TodoList();
                a.Description = value.Description;
                a.isDeleted   = false;
                a.Name        = value.Name;
                a.StatusId    = 1;
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                entities.TodoLists.Add(a);

                int i = entities.SaveChanges();
                if (i == 0)
                {
                    return(Conflict());
                }
                return(Created <TodoList>(Request.RequestUri + a.Id.ToString(), a));
            }
        }
예제 #2
0
        public IHttpActionResult Put(int id, [FromBody] TodoModel value)
        {
            if (value == null)
            {
                return(BadRequest("Product cannot be null"));
            }

            using (TodoEntities1 entities = new TodoEntities1())
            {
                TodoList a = entities.TodoLists.Where(item => item.Id == id).FirstOrDefault();
                if (a == null)
                {
                    return(BadRequest("Product not Found"));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                a.Description = value.Description;
                a.isDeleted   = value.isDeleted;
                a.Name        = value.Name;
                a.StatusId    = value.StatusId;
                int i = entities.SaveChanges();
                return(Ok());
            }
        }
예제 #3
0
 public IHttpActionResult Delete(int id)
 {
     if (id < 0)
     {
         return(BadRequest("Product not found"));
     }
     using (TodoEntities1 entities = new TodoEntities1())
     {
         var entity = entities.TodoLists.Where(a => a.Id == id).FirstOrDefault();
         if (entity == null)
         {
             return(BadRequest("Product not Found"));
         }
         entity.isDeleted = true;
         int i = entities.SaveChanges();
         if (i == 0)
         {
             return(Conflict());
         }
         return(Ok());
     }
 }