public async Task <IActionResult> Create([Bind("MinMaxDevId,ValueKey,MinDev,MaxDev")] MinMaxDevRange minMaxDevRange) { if (ModelState.IsValid) { _context.Add(minMaxDevRange); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(minMaxDevRange)); }
public async Task <IActionResult> Edit(int id, [Bind("MinMaxDevId,ValueKey,MinDev,MaxDev")] MinMaxDevRange minMaxDevRange) { if (minMaxDevRange is null || id != minMaxDevRange.MinMaxDevId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(minMaxDevRange); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!MinMaxDevRangeExists(minMaxDevRange.MinMaxDevId)) { return(NotFound()); } return(RedirectToAction(nameof(Index))); } return(View(minMaxDevRange)); }
public string SetRangeToChampionship(Championship championship, bool isAgeDev, IList <int> valueKeys, IList <int> valueMins, IList <int> valueMaxs) { // Null check to ensure all given parameters actually contain a value if (championship is null || valueKeys is null || valueMins is null || valueMaxs is null) { return("Values couldn't be read"); } string errString = ""; // This ensures the lists are of equal length, if this isn't the case then it returns a string errString += MinMaxDevValidator.ValidateListsEqualLength(valueKeys.Count, valueMins.Count, valueMaxs.Count); // We have to ensure that the order of the keys are correct, otherwise returns a bad errString += MinMaxDevValidator.CheckIfListIsInOrder(valueKeys); // If the lists are neither in order nor have an equal length then we return it if (!string.IsNullOrEmpty(errString)) { return(errString); } // Empties either of the dev ranges so we can put in some new ones (owo) if (isAgeDev) { Context.MinMaxDevRange.RemoveRange(championship.AgeDevRanges); } else { Context.MinMaxDevRange.RemoveRange(championship.SkillDevRanges); } // Loops through all the key values which assumes that the age value, min dev and max dev lists are of the same length for (int i = 0; i < valueKeys.Count; i++) { // Creates an MinMax object from the given lists, assuming they are made equally MinMaxDevRange newDevRange = new MinMaxDevRange { ValueKey = valueKeys[i], MinDev = valueMins[i], MaxDev = valueMaxs[i] }; // Validates the current entry var validate = MinMaxDevValidator.ValidateMinMax(newDevRange); if (!validate.IsValid) { foreach (var failure in validate.Errors) { errString += $"{failure.ErrorMessage} "; } } else { // Validator didn't trigger so this line can be added to the ranges if (isAgeDev) { championship.AgeDevRanges.Add(newDevRange); } else { championship.SkillDevRanges.Add(newDevRange); } } } return(errString); }