コード例 #1
0
 public ActionResult Edit(Cider cider, int MakerId, int StyleId, int AppleId)
 {
     if (MakerId != 0)
     {
         _db.CiderMaker.Add(new CiderMaker()
         {
             MakerId = MakerId, CiderId = cider.CiderId
         });
     }
     if (AppleId != 0)
     {
         _db.AppleCider.Add(new AppleCider()
         {
             AppleId = AppleId, CiderId = cider.CiderId
         });
     }
     if (StyleId != 0)
     {
         _db.CiderStyle.Add(new CiderStyle()
         {
             StyleId = StyleId, CiderId = cider.CiderId
         });
     }
     _db.Entry(cider).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = cider.CiderId }));
 }
コード例 #2
0
        public async Task <ActionResult> Create(Cider cider)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            cider.User = currentUser;
            _db.Ciders.Add(cider);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 public ActionResult AddStyle(Cider cider, int StyleId)
 {
     if (StyleId != 0)
     {
         _db.CiderStyle.Add(new CiderStyle()
         {
             StyleId = StyleId, CiderId = cider.CiderId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = cider.CiderId }));
 }
コード例 #4
0
 public ActionResult AddCider(Cider cider, int AppleId)
 {
     if (AppleId != 0)
     {
         _db.AppleCider.Add(new AppleCider()
         {
             AppleId = AppleId, CiderId = cider.CiderId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = cider.CiderId }));
 }
コード例 #5
0
 public ActionResult AddMaker(Cider cider, int MakerId)
 {
     if (MakerId != 0)
     {
         _db.CiderMaker.Add(new CiderMaker()
         {
             MakerId = MakerId, CiderId = cider.CiderId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Details", new { id = cider.CiderId }));
 }
コード例 #6
0
        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"));
        }
コード例 #7
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));
        }