public Task <IActionResult> Edit(UserInputModel userInputModel, RolesOperations rolesOperations) { var button = rolesOperations.Button; if (button == ControllerConstants.CANCEL) { return(Task.FromResult((IActionResult)RedirectToAction(nameof(Index)))); } else if (button == ControllerConstants.SAVE) { return(HandleWithSave(userInputModel)); } else { return(HandleWithRoles(userInputModel, rolesOperations)); } }
private Task <IActionResult> HandleWithRoles(UserInputModel userInputModel, RolesOperations rolesOperations) { var button = rolesOperations.Button; var roleValue = rolesOperations.RoleValue; if (userInputModel.Roles == null) { userInputModel.Roles = new List <string>(); } if (button.Contains(ControllerConstants.ADD_TO_LIST)) { userInputModel.Roles.Add(roleValue); } else if (button.Contains(ControllerConstants.REMOVE_FROM_LIST)) { userInputModel.Roles.Remove(roleValue); } ModelState.Clear(); return(ReturnEditView(userInputModel)); }
/// <summary> /// This method is used to retrieve the data of roles through an API request and print the response. /// </summary> public static void GetRoles() { //Get instance of RolesOperations Class RolesOperations rolesOperations = new RolesOperations(); //Call GetRoles method APIResponse <ResponseHandler> response = rolesOperations.GetRoles(); if (response != null) { //Get the status code from response Console.WriteLine("Status Code: " + response.StatusCode); if (new List <int>() { 204, 304 }.Contains(response.StatusCode)) { Console.WriteLine(response.StatusCode == 204 ? "No Content" : "Not Modified"); return; } //Check if expected response is received if (response.IsExpected) { //Get object from response ResponseHandler responseHandler = response.Object; if (responseHandler is ResponseWrapper) { //Get the received ResponseWrapper instance ResponseWrapper responseWrapper = (ResponseWrapper)responseHandler; //Get the list of obtained Role instances List <Com.Zoho.Crm.API.Roles.Role> roles = responseWrapper.Roles; foreach (Com.Zoho.Crm.API.Roles.Role role in roles) { //Get the DisplayLabel of each Role Console.WriteLine("Role DisplayLabel: " + role.DisplayLabel); //Get the forecastManager User instance of each Role User forecastManager = role.ForecastManager; //Check if forecastManager is not null if (forecastManager != null) { //Get the ID of the forecast Manager Console.WriteLine("Role Forecast Manager User-ID: " + forecastManager.Id); //Get the name of the forecast Manager Console.WriteLine("Role Forecast Manager User-Name: " + forecastManager.Name); } //Get the ShareWithPeers of each Role Console.WriteLine("Role ShareWithPeers: " + role.ShareWithPeers); //Get the Name of each Role Console.WriteLine("Role Name: " + role.Name); //Get the Description of each Role Console.WriteLine("Role Description: " + role.Description); //Get the Id of each Role Console.WriteLine("Role ID: " + role.Id); //Get the reportingTo User instance of each Role User reportingTo = role.ReportingTo; //Check if reportingTo is not null if (reportingTo != null) { //Get the ID of the reportingTo User Console.WriteLine("Role ReportingTo User-ID: " + reportingTo.Id); //Get the name of the reportingTo User Console.WriteLine("Role ReportingTo User-Name: " + reportingTo.Name); } //Get the AdminUser of each Role Console.WriteLine("Role AdminUser: "******"Status: " + exception.Status.Value); //Get the Code Console.WriteLine("Code: " + exception.Code.Value); Console.WriteLine("Details: "); //Get the details map foreach (KeyValuePair <string, object> entry in exception.Details) { //Get each value in the map Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value)); } //Get the Message Console.WriteLine("Message: " + exception.Message.Value); } } else { //If response is not as expected //Get model object from response Model responseObject = response.Model; //Get the response object's class Type type = responseObject.GetType(); //Get all declared fields of the response class Console.WriteLine("Type is: {0}", type.Name); PropertyInfo[] props = type.GetProperties(); Console.WriteLine("Properties (N = {0}):", props.Length); foreach (var prop in props) { if (prop.GetIndexParameters().Length == 0) { Console.WriteLine("{0} ({1}) : {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject)); } else { Console.WriteLine("{0} ({1}) : <Indexed>", prop.Name, prop.PropertyType.Name); } } } } }