Example #1
0
        //Update/Edit Pizzas -EAC

        public bool UpdatePizza(PizzaEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx
                             .PizzaTable
                             .Single(e => e.PizzaId == model.PizzaId);

                entity.PizzaId            = model.PizzaId;
                entity.OrderId            = model.OrderId;
                entity.UserId             = model.UserId;     //EAC: do we want to be able to edit EmployeeId in a pizza? I think probably not
                entity.CustomerId         = model.CustomerId; //EAC same note as EmployeeId
                entity.Cheese             = model.Cheese;
                entity.TypeOfCrust        = model.TypeOfCrust;
                entity.TypeOfSauce        = model.TypeOfSauce;
                entity.TypeOfSize         = model.TypeOfSize;
                entity.TypeOfToppingOne   = model.TypeOfToppingOne;
                entity.TypeOfToppingTwo   = model.TypeOfToppingTwo;
                entity.TypeOfToppingThree = model.TypeOfToppingThree;
                entity.TypeOfToppingFour  = model.TypeOfToppingFour;
                entity.TypeOfToppingFive  = model.TypeOfToppingFive;
                entity.Comment            = model.Comment;
                entity.ModifiedUtc        = DateTimeOffset.UtcNow;
                return(ctx.SaveChanges() == 1);
            }
        }
        public IHttpActionResult EditPizza(PizzaEdit pizza)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreatePizzaService();

            if (!service.UpdatePizza(pizza))
            {
                return(InternalServerError());
            }

            return(Ok());
        }