コード例 #1
0
        public bool UpdateCake(CakeEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Cakes
                    .Single(e => e.CakeId == model.CakeId && e.UserId == _userId);
                if (model.Flavor != null)
                {
                    entity.Flavor = model.Flavor;
                }

                if (model.Icing != null)
                {
                    entity.Icing = model.Icing;
                }
                if (model.Toppings != null)
                {
                    entity.Toppings = model.Toppings;
                }


                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #2
0
        public IHttpActionResult Put(CakeEdit cake)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCakeService();

            if (!service.UpdateCake(cake))
            {
                return(InternalServerError());
            }
            return(Ok());
        }