示例#1
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));
        }
示例#2
0
        public IHttpActionResult PutPhoneNumber(int id, PhoneNumber phoneNumber)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#3
0
        public IHttpActionResult PutSaleUnit(int id, SaleUnit saleUnit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SaleUnitExists(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));
        }
        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));
        }
示例#6
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));
        }
示例#7
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));
        }
示例#8
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));
        }