Ejemplo n.º 1
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    var originalShop = db.shops.Find(id);
                    if (originalShop != null)
                    {
                        db.shops.Remove(originalShop);
                        db.SaveChanges();
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "shop id not recognized"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Put([FromBody] Models.shop updatedShop)
        {
            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    var originalShop = db.shops.Find(updatedShop.ShopId);
                    if (originalShop != null)
                    {
                        db.Entry(originalShop).CurrentValues.SetValues(updatedShop);
                        db.SaveChanges();
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "shop id not recognized"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(updatedShop)));
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    var originalUser = db.users.Find(id);
                    if (originalUser != null)
                    {
                        db.users.Remove(originalUser);
                        db.SaveChanges();
                    }
                    else
                    {
                        return Request.CreateErrorResponse(HttpStatusCode.NotFound, "user id not recognized");
                    }
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Post([FromBody] Models.shop newShop)
        {
            try
            {
                newShop.ShopId = 0;

                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    db.shops.Add(newShop);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(newShop)));
        }
Ejemplo n.º 5
0
        public HttpResponseMessage Put([FromBody]Models.user updatedUser)
        {
            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    var originalUser = db.users.Find(updatedUser.UserId);
                    if(originalUser != null)
                    {
                        db.Entry(originalUser).CurrentValues.SetValues(updatedUser);
                        db.SaveChanges();
                    }
                    else
                    {
                        return Request.CreateErrorResponse(HttpStatusCode.NotFound, "user id not recognized");
                    }
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(updatedUser));
        }
Ejemplo n.º 6
0
        public HttpResponseMessage Post([FromBody]Models.user newUser)
        {
            try
            {
                newUser.UserId = 0;

                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    db.users.Add(newUser);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(newUser));
        }