private dynamic PerformAction() { RequiresUser(LcData.UserInfo.UserType.ServiceProfessional); // Two segments: // - jobTitleID // - actionName to execute if (UrlData.Count == 2) { if (UrlData[0].IsInt()) { // Response must be OK if goes fine (by default for POST is 'Created' // it does not apply on this case) WebPage.Response.StatusCode = 200; // Parameters int userID = WebSecurity.CurrentUserId; var jobTitleID = UrlData[0].AsInt(); // Result holders var done = false; switch (UrlData[1].ToLower()) { case "deactivate": done = LcData.JobTitle.DeactivateUserJobTitle(userID, jobTitleID); // It cannot be done if record not exists, notify: if (!done) { throw new HttpException(404, "Not found"); } else { // Return an updated item return(GetItem(userID, jobTitleID)); } case "reactivate": // Double check if item exists if (GetItem(userID, jobTitleID) == null) { throw new HttpException(404, "Not found"); } else { done = LcData.JobTitle.ReactivateUserJobTitle(userID, jobTitleID); if (!done) { // It cannot be done, since we already know // that the record exists, the problem only can // be that constraints for 'active profile' were not // fullfilled to allow manual activation. // Notify about pending steps: var alertsMsg = "You must complete another {0} steps to activate this profile."; var alerts = LcData.GetActiveRequiredUserAlertsCount(userID, jobTitleID); throw new HttpException(400, String.Format(alertsMsg, alerts)); } else { // Return an updated item return(GetItem(userID, jobTitleID)); } } default: throw new HttpException(404, "Not found"); } } else { throw new HttpException(400, "Invalid Job Title ID"); } } throw new HttpException(404, "Not found"); }