public async Task <IActionResult> Relation(RelationModel model) { var user = await userManager.GetUserAsync(User); if (user == null || !(await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.VolunteerCaptain.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.BusDriver.ToString()) || await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString()))) { return(Utilities.ErrorJson("Not authorized.")); } List <String> missingParameters = new List <String>(); int missingIds = 0; if (model.ChildId1 == 0) { missingIds++; } if (model.ChildId2 == 0) { missingIds++; } if (model.Relation == null) { missingParameters.Add("relationship"); } if (missingIds > 0) { missingParameters.Add(missingIds + " more child id" + (missingIds == 2 ? "s" : "")); } if (missingParameters.Count > 0) { return(Utilities.GenerateMissingInputMessage(missingParameters)); } if (model.ChildId1 == model.ChildId2) { return(new JsonResult(new { Error = "Children ids cannot be the same." })); } try { ChildRepository repo = new ChildRepository(configModel.ConnectionString); return(new JsonResult(new { Message = repo.AddRelation(model) })); } catch (Exception exc) { return(new JsonResult(new { Error = exc.Message, })); } }