public ActionResult RemoveFlavor(int id) { TreatFlavor joinEntry = _db.TreatFlavors.FirstOrDefault(x => x.TreatFlavorId == id); int treatId = joinEntry.TreatId; _db.TreatFlavors.Remove(joinEntry); _db.SaveChanges(); return(RedirectToAction("details", "treats", new { id = treatId })); }
public ActionResult RemoveTreat(int FlavorId, int TreatId) { if (TreatId != 0 && FlavorId != 0) { TreatFlavor thisTreatFlavor = _db.TreatFlavor.FirstOrDefault(join => join.Flavor.FlavorId == FlavorId && join.Treat.TreatId == TreatId); _db.TreatFlavor.Remove(thisTreatFlavor); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult AddTreatToFlavor(int flavorId, int treatId) { var thisTreat = _db.Treats.FirstOrDefault(treat => treat.TreatId == treatId); var thisFlavor = _db.Flavors.FirstOrDefault(flavor => flavor.FlavorId == flavorId); var treatFlavor = new TreatFlavor(); treatFlavor.Flavor = thisFlavor; treatFlavor.Treat = thisTreat; _db.TreatFlavor.Add(treatFlavor); _db.SaveChanges(); return(RedirectToAction("Details", new { id = flavorId })); }
public ActionResult AddFlavor(TreatFlavor treatFlavor) { if (treatFlavor.FlavorId != 0) { if (_db.TreatFlavors.Where(x => x.TreatId == treatFlavor.TreatId && x.FlavorId == treatFlavor.FlavorId).ToHashSet().Count == 0) { _db.TreatFlavors.Add(treatFlavor); } } _db.SaveChanges(); return(RedirectToAction("details", new { id = treatFlavor.TreatId })); }
public async Task <ActionResult> Create(TreatFlavor treatFlavor) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var currentUser = await _userManager.FindByIdAsync(userId); treatFlavor.User = currentUser; _db.TreatFlavor.Add(treatFlavor); // if (EmployeeId != 0) // { // _db.EmployeeKind.Add(new EmployeeKind() { EmployeeId = EmployeeId, KindId = kind.KindId }); // } _db.SaveChanges(); return(RedirectToAction("Index")); }