Example #1
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)));
        }
Example #2
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));
        }
        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);
        }
Example #4
0
 public static List <Models.user> GetUsers()
 {
     try
     {
         using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
         {
             return(db.users.ToList());
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Error retrieving user list", ex);
     }
 }
 public static List<Models.user> GetUsers()
 {
     try
     {
         using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
         {
             return db.users.ToList();
         }
     }
     catch(Exception ex)
     {
         throw new Exception("Error retrieving user list", ex);
     }
 }
Example #6
0
 public static Models.user GetUser(int userId)
 {
     Models.user thisUser;
     try {
         using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
         {
             thisUser = db.users.SingleOrDefault(s => s.UserId == userId);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Error finding user", ex);
     }
     return(thisUser);
 }
 public static Models.user GetUser(int userId)
 {
     Models.user thisUser;
     try {
         using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
         {
             thisUser = db.users.SingleOrDefault(s => s.UserId == userId);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Error finding user", ex);
     }
     return thisUser;
 }
Example #8
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)));
        }
Example #9
0
        public HttpResponseMessage Get()
        {
            JArray shops = new JArray();

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    foreach (Models.shop s in db.shops)
                    {
                        shops.Add(JObject.FromObject(s));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, shops));
        }
        public HttpResponseMessage Get()
        {
            JArray shops = new JArray();

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    foreach (Models.shop s in db.shops)
                    {
                        shops.Add(JObject.FromObject(s));
                    }
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, shops);
        }
Example #11
0
        public HttpResponseMessage Get(int id)
        {
            Models.shop thisShop;

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    thisShop = db.shops.SingleOrDefault(s => s.ShopId == id);

                    if (thisShop == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "shop id " + id.ToString() + " not found"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(thisShop)));
        }
        public HttpResponseMessage GetUser(int id)
        {
            Models.user thisUser;

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    thisUser = db.users.SingleOrDefault(s => s.UserId == id);

                    if(thisUser == null)
                    {
                        return Request.CreateErrorResponse(HttpStatusCode.NotFound, "user id " + id.ToString() + " not found");
                    }
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, JObject.FromObject(thisUser));
        }
Example #13
0
        public HttpResponseMessage GetRuns(int id)
        {
            List <Models.run> runs     = new List <Models.run>();
            JArray            runArray = new JArray();

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    runs = db.runs.Where(s => s.ShopId == id).ToList();

                    foreach (Models.run r in runs)
                    {
                        runArray.Add(JToken.FromObject(r));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, runArray));
        }
Example #14
0
        public HttpResponseMessage GetOrders(int id)
        {
            List <Models.order> orders = new List <Models.order>();
            JArray orderArray          = new JArray();

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    orders = db.orders.SqlQuery("select * from orders o join runs r on o.runid = r.runid where r.shopid = shopIdParam", new SqlParameter("shopIdParam", id)).ToList();

                    foreach (Models.order o in orders)
                    {
                        orderArray.Add(JToken.FromObject(o));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, orderArray));
        }
        public HttpResponseMessage GetOrders(int id)
        {
            List<Models.order> orders = new List<Models.order>();
            JArray orderArray = new JArray();

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    orders = db.orders.SqlQuery("select * from orders o join runs r on o.runid = r.runid where r.shopid = shopIdParam", new SqlParameter("shopIdParam",id)).ToList();

                    foreach (Models.order o in orders)
                    {
                        orderArray.Add(JToken.FromObject(o));
                    }
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, orderArray);
        }
        public HttpResponseMessage GetRuns(int id)
        {
            List<Models.run> runs = new List<Models.run>();
            JArray runArray = new JArray();

            try
            {
                using (var db = new SONRCoffee.Data.SONRCoffeeDbContext())
                {
                    runs = db.runs.Where(s => s.ShopId == id).ToList();

                    foreach(Models.run r in runs)
                    {
                        runArray.Add(JToken.FromObject(r));
                    }
                }
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, runArray);
        }
        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));
        }
        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));
        }