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 })); }
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")); }
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 })); }
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 })); }
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 })); }
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")); }
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)); }