Esempio n. 1
0
        public IHttpActionResult Delete(int intKey)
        {
            var context = new MultiBufferContext();

            var query =
                from el in context.BufferItems
                where el.Key == intKey
                select el;

            BufferItem item = query.SingleOrDefault();

            if (item != null)
            {
                try
                {
                    context.BufferItems.Remove(item);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(BadRequest("Item is already not existing"));
            }
        }
Esempio n. 2
0
 public void MultiBufferContextTest()
 {
     using (var context = new MultiBufferContext())
     {
         var bufferItem = new BufferItem()
         {
             Key   = 0,
             Name  = "Zero",
             Value = "000"
         };
         context.BufferItems.Add(bufferItem);
         context.SaveChanges();
     }
     Assert.IsTrue(true);
 }
Esempio n. 3
0
        public IHttpActionResult Create(int intKey, BufferItem bufferItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (intKey != bufferItem.Key)
            {
                return(BadRequest("Wrong data"));
            }

            var context = new MultiBufferContext();
            var query   =
                from el in context.BufferItems
                where el.Key == intKey
                select el;

            BufferItem item = query.SingleOrDefault();

            if (item == null)
            {
                try
                {
                    bufferItem.Id = 0;
                    context.BufferItems.Add(bufferItem);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
                return(StatusCode(HttpStatusCode.NoContent));
            }
            else
            {
                return(BadRequest("Item is already existing"));
            }
        }