Example #1
0
        public IHttpActionResult Post(CakeCreate cake)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCakeService();

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

            return(Ok());
        }
Example #2
0
        public bool CreateCake(CakeCreate model)
        {
            var entity =
                new Cake()
            {
                UserId   = _userId,
                Flavor   = model.Flavor,
                Toppings = model.Toppings,
                Icing    = model.Icing,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cakes.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }