public ActionResult DoIt(MakeCiderRequest req)
        {
            var db = new AppDbContext();

            var bushel   = db.Bushels.Find(req.BushelId);
            var newCider = new Cider
            {
                Bushel          = bushel,
                DatePressed     = DateTime.Now,
                NumberOfGallons = bushel.Quantity * 3,
                Type            = bushel.Type
            };

            db.Ciders.Add(newCider);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public HttpResponseMessage MakeCider(MakeCiderRequest makeCiderRequest)
        {
            var db = new AppDbContext();

            var bushel = db.Bushels.Find(makeCiderRequest.BushelId);

            if (bushel == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No bushel with the given id exists"));
            }
            if (bushel.Pressed)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "This bushel has already been pressed"));
            }

            bushel.Pressed = true;

            var newCider = new Cider
            {
                Type            = bushel.Type,
                Bushel          = bushel,
                DatePressed     = DateTime.Now,
                Filtered        = false,
                NumberOfGallons = bushel.Quantity * 3
            };

            db.Ciders.Add(newCider);

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                //log.error(ex);
                Request.CreateErrorResponse(HttpStatusCode.InternalServerError,
                                            "Couldn't make cider today, Machine is down for repairs.");
            }

            return(Request.CreateResponse(HttpStatusCode.Created, newCider));
        }