Esempio n. 1
0
        public async Task <IActionResult> PutOrder(int id, Order order)
        {
            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Response.Headers.Add("Access-Control-Allow-Credentials", "true");
            Response.Headers.Add("Access-Control-Allow-Headers", "*");
            Response.Headers.Add("Access-Control-Allow-Methods", "PUT");
            if (id != order.OrderId)
            {
                return(BadRequest());
            }

            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 2
0
        public async Task<IActionResult> PutCustomer(int id, Customer customer)
        {

            if (id != customer.Id)
            {
                return BadRequest();
            }

            var isvalid = await _context.Customers
                .Where(o => customer.Id != o.Id && (o.Email.ToLower() == customer.Email.ToLower() || o.phoneNumber == customer.phoneNumber))
                .FirstOrDefaultAsync();
            if (isvalid != null)
                return BadRequest();

            _context.Entry(customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
Esempio n. 3
0
        public async Task <IActionResult> PutOrder(int id, Order order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutPizza([FromRoute] int id, [FromBody] Pizza pizza)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pizza.Id)
            {
                return(BadRequest());
            }

            _context.Entry(pizza).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PizzaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 5
0
        public IActionResult Update(Pizza updatedPizza)
        {
            if (_context.Pizza.Count(e => e.PizzaName == updatedPizza.PizzaName) == 0)
            {
                return(NotFound());
            }

            _context.Pizza.Attach(updatedPizza);
            _context.Entry(updatedPizza).State = EntityState.Modified;
            _context.SaveChanges();

            return(Ok(updatedPizza));
        }
        public IActionResult Update(Person updatedPerson)
        {
            if (_context.Person.Count(e => e.Name == updatedPerson.Name) == 0)
            {
                return(NotFound());
            }

            _context.Person.Attach(updatedPerson);
            _context.Entry(updatedPerson).State = EntityState.Modified;
            _context.SaveChanges();

            return(Ok(updatedPerson));
        }
Esempio n. 7
0
        public IActionResult Update(Ingredient updatedIngredient)
        {
            if (_context.Ingredient.Count(e => e.IngredientName == updatedIngredient.IngredientName) == 0)
            {
                return(NotFound());
            }

            _context.Ingredient.Attach(updatedIngredient);
            _context.Entry(updatedIngredient).State = EntityState.Modified;
            _context.SaveChanges();

            return(Ok(updatedIngredient));
        }
Esempio n. 8
0
        public async Task <IActionResult> DeletePizzaItem(long orderNumber)
        {
            if (orderNumber <= 0)
            {
                return(BadRequest("Invalid order number"));
            }

            var pizzaOrders = from p in _pizzaContext.PizaaItems
                              select p;

            var pizzaOrder = pizzaOrders.Where(p => p.OrderNumber == orderNumber);

            if (pizzaOrder == null)
            {
                return(NotFound("the order number does not match with any of the avaliable orders"));
            }

            _pizzaContext.Entry(pizzaOrder).State = EntityState.Deleted;
            await _pizzaContext.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 9
0
        public async Task <IActionResult> AddEditPizza(AddEditPizzaModel newPizzaModel)
        {
            var newPizza = newPizzaModel.Pie;

            if (!ModelState.IsValid)
            {
                return(View(newPizzaModel));
            }

            var pizza = _pizzaContext.Pies.FirstOrDefault(a => a.Id == newPizza.Id) ?? new Pie();

            if (pizza == null)
            {
                pizza = new Pie();
            }
            pizza.Name             = newPizza.Name;
            pizza.ShortDescription = newPizza.ShortDescription ?? "";
            pizza.LongDescription  = newPizza.LongDescription ?? "";
            pizza.Price            = newPizza.Price;
            pizza.IsPieOfTheWeek   = newPizza.IsPieOfTheWeek;
            //pizza.ImageUrl = newPizza.ImageUrl ?? "";
            //pizza.ImageThumbnailUrl = newPizza.ImageThumbnailUrl ?? "";


            if (newPizzaModel.Image != null)
            {
                pizza.SetImage(newPizzaModel.Image);
            }
            else
            {
                if (Id != 0)
                {
                    var tempPizza = _pizzaContext.Pies.FirstOrDefault(a => a.Id == newPizza.Id);
                    pizza.Image            = tempPizza.Image;
                    pizza.ImageContentType = tempPizza.ImageContentType;
                }
            }

            _pizzaContext.Entry(pizza).State = pizza.Id == default(long) ? EntityState.Added : EntityState.Modified;
            await _pizzaContext.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 10
0
 public virtual async Task Update(T entity)
 {
     _db.Entry(entity).State = EntityState.Modified;
     await _db.SaveChangesAsync();
 }