public IHttpActionResult PutPriceRange(int id, PriceRange priceRange)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != priceRange.ID)
            {
                return(BadRequest());
            }

            db.Entry(priceRange).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PriceRangeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutOrderProduct(int id, OrderProduct orderProduct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != orderProduct.Order_FK)
            {
                return(BadRequest());
            }

            db.Entry(orderProduct).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutDeleveryDelay(int id, DeleveryDelay deleveryDelay)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != deleveryDelay.ID)
            {
                return(BadRequest());
            }

            db.Entry(deleveryDelay).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeleveryDelayExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 4
0
        public IHttpActionResult PutPastryShopDeleveryMethod(int id, PastryShopDeleveryMethod pastryShopDeleveryMethod)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pastryShopDeleveryMethod.PastryShop_FK)
            {
                return(BadRequest());
            }

            db.Entry(pastryShopDeleveryMethod).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PastryShopDeleveryMethodExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 5
0
        public IHttpActionResult PutPassword(string email, string newPassword)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user = db.Users.FirstOrDefault(u => u.Email == email);

            if (user == null)
            {
                var pastryShop = db.PastryShops.FirstOrDefault(u => u.Email == email);
                if (pastryShop != null)
                {
                    pastryShop.Password        = newPassword;
                    db.Entry(pastryShop).State = EntityState.Modified;
                }
            }
            else
            {
                user.Password        = newPassword;
                db.Entry(user).State = EntityState.Modified;
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 6
0
        public IHttpActionResult PutPastryShopCategories(int id, PastryShop pastryShop)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pastryShop.ID)
            {
                return(BadRequest());
            }

            var existingPastry     = db.PastryShops.FirstOrDefault(p => p.ID == id);
            var toDeleteCategories = existingPastry.Categories.Except(pastryShop.Categories, c => c.ID).ToList <Category>();
            var toAddCategories    = pastryShop.Categories.Except(existingPastry.Categories, c => c.ID).ToList <Category>();

            toDeleteCategories.ForEach(c => existingPastry.Categories.Remove(c));
            foreach (var category in toAddCategories)
            {
                if (db.Entry(category).State == EntityState.Detached)
                {
                    db.Categories.Attach(category);
                }
                existingPastry.Categories.Add(category);
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PastryShopExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 7
0
        public IHttpActionResult MarkAsSeenPastryShop(int id)
        {
            Order order = db.Orders.Find(id);

            order.SeenPastryShop  = true;
            db.Entry(order).State = EntityState.Modified;
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 8
0
 private static void CheckMethod()
 {
     while (true)
     {
         var x = TimeSpan.FromDays(1);
         Thread.Sleep(x);
         using (var db = new KmandiliDBEntities())
         {
             var toCompareDate  = DateTime.Now.Date;
             var toDeleteOrders = db.Orders.Where(o => (o.Status_FK == 1) && (toCompareDate == DbFunctions.TruncateTime(DbFunctions.AddDays(o.Date, 2))));
             toDeleteOrders.ForEach(SendCanceledEmail);
             db.Orders.RemoveRange(toDeleteOrders);
             db.SaveChanges();
         }
     }
 }