public bool CheckIfExists(ShiftLengths shiftLength) { var count = _context.ShiftLengths.Select(s => s.Shift).Where(s => s.Equals(shiftLength.Shift)).Count(); if (count > 0) { return(true); } return(false); }
public ActionResult NewShift(ShiftLengths newShift) { try { newShift.Shift = Convert.ToDouble(newShift.Shift); bool exists = CheckIfExists(newShift); if (!exists) { newShift.Display = true; _context.ShiftLengths.Add(newShift); _context.SaveChanges(); } else { return(RedirectToAction(RetryDialogueBox("This input already exists. Click retry to enter a new number.", "Duplicate Input.", "AddShiftLengths"))); } } catch { return(RedirectToAction(RetryDialogueBox("Input can only contain a number. Click retry to enter a new number.", "Invalid Input.", "AddShiftLengths"))); } return(RedirectToAction("AddShiftLengths")); }