public ActionResult Details(string course) { Course courseObject = new Course(); courseObject.CourseId = course; Models.Participant participant = new Models.Participant(); participant.ParticipantId = 1; List <Course> courses = manager.GetCourses(1, participant); IEnumerable <SelectListItem> selectList = from c in courses select new SelectListItem { Value = c.CourseId.ToString(), Text = c.Name }; ViewData["Courses"] = new SelectList(selectList, "Value", "Text"); List <ClassesUnit> classesUnits = manager.GetClassesUnitsDate(courseObject); List <Attendance> attendances = manager.GetAttendances(participant, courseObject); ViewBag.attendancesAvailable = classesUnits.Count > 0; List <bool> attendancesBool = new List <bool>(); foreach (ClassesUnit unit in classesUnits) { bool found = false; foreach (Attendance item in attendances) { if (unit.ClassUnitId == item.ClassesUnit.ClassUnitId) { found = true; break; } } attendancesBool.Add(found); } ViewData["classesUnits"] = classesUnits; ViewData["attendancesBool"] = attendancesBool; int presentQuantity = 0; int absentQuantity = 0; foreach (var item in attendancesBool) { if (item) { presentQuantity++; } else { absentQuantity++; } } int classUnitQuantity = presentQuantity + absentQuantity; int absentPercentage = 0; int presentPercentage = 0; if (classUnitQuantity != 0) { absentPercentage = (int)(absentQuantity / (double)classUnitQuantity * 100); presentPercentage = (int)(presentQuantity / (double)classUnitQuantity * 100); } ViewData["presentQuantity"] = presentQuantity; ViewData["absentQuantity"] = absentQuantity; ViewData["classUnitQuantity"] = classUnitQuantity; ViewData["absentPercentage"] = absentPercentage; ViewData["presentPercentage"] = presentPercentage; return(View()); }
public AccountsParticipantsResponse(Models.Participant participant = null, string token = null) { Participant = participant; Token = token; }
/// <summary> /// Create a new participant under this account /// Participants are idempotent, so relevant parameters must be set in this function if desired /// </summary> /// <param name="accountId">Required parameter: Account ID</param> /// <param name="body">Optional parameter: Participant parameters</param> /// <return>Returns the ApiResponse<Models.AccountsParticipantsResponse> response from the API call</return> public async Task <ApiResponse <Models.AccountsParticipantsResponse> > CreateParticipantAsync(string accountId, Models.Participant body = null, CancellationToken cancellationToken = default) { //the base uri for api requests string _baseUri = config.GetBaseUri(Server.WebRtcDefault); //prepare query string for API call StringBuilder _queryBuilder = new StringBuilder(_baseUri); _queryBuilder.Append("/accounts/{accountId}/participants"); //process optional template parameters ApiHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>() { { "accountId", accountId } }); //append request with appropriate headers and parameters var _headers = new Dictionary <string, string>() { { "user-agent", userAgent }, { "accept", "application/json" }, { "content-type", "application/json; charset=utf-8" } }; //append body params var _body = ApiHelper.JsonSerialize(body); //prepare the API call request to fetch the response HttpRequest _request = GetClientInstance().PostBody(_queryBuilder.ToString(), _headers, _body); _request = await authManagers["webRtc"].ApplyAsync(_request).ConfigureAwait(false); //invoke request and get response HttpStringResponse _response = await GetClientInstance().ExecuteAsStringAsync(_request, cancellationToken).ConfigureAwait(false); HttpContext _context = new HttpContext(_request, _response); //Error handling using HTTP status codes if (_response.StatusCode == 400) { throw new ApiException("Bad Request", _context); } if (_response.StatusCode == 401) { throw new ApiException("Unauthorized", _context); } if (_response.StatusCode == 403) { throw new ApiException("Access Denied", _context); } if ((_response.StatusCode < 200) || (_response.StatusCode > 208)) //[200,208] = HTTP OK { throw new ErrorException("Unexpected Error", _context); } //handle errors defined at the API level base.ValidateResponse(_response, _context); var _result = ApiHelper.JsonDeserialize <Models.AccountsParticipantsResponse>(_response.Body); ApiResponse <Models.AccountsParticipantsResponse> apiResponse = new ApiResponse <Models.AccountsParticipantsResponse>(_response.StatusCode, _response.Headers, _result); return(apiResponse); }
/// <summary> /// Create a new participant under this account. /// Participants are idempotent, so relevant parameters must be set in this function if desired. /// </summary> /// <param name="accountId">Required parameter: Account ID.</param> /// <param name="body">Optional parameter: Participant parameters.</param> /// <param name="cancellationToken"> cancellationToken. </param> /// <returns>Returns the ApiResponse of Models.AccountsParticipantsResponse response from the API call.</returns> public async Task <ApiResponse <Models.AccountsParticipantsResponse> > CreateParticipantAsync( string accountId, Models.Participant body = null, CancellationToken cancellationToken = default) { // the base uri for api requests. string baseUri = this.Config.GetBaseUri(Server.WebRtcDefault); // prepare query string for API call. StringBuilder queryBuilder = new StringBuilder(baseUri); queryBuilder.Append("/accounts/{accountId}/participants"); // process optional template parameters. ApiHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>() { { "accountId", accountId }, }); // append request with appropriate headers and parameters var headers = new Dictionary <string, string>() { { "user-agent", this.UserAgent }, { "accept", "application/json" }, { "content-type", "application/json; charset=utf-8" }, }; // append body params. var bodyText = ApiHelper.JsonSerialize(body); // prepare the API call request to fetch the response. HttpRequest httpRequest = this.GetClientInstance().PostBody(queryBuilder.ToString(), headers, bodyText); if (this.HttpCallBack != null) { this.HttpCallBack.OnBeforeHttpRequestEventHandler(this.GetClientInstance(), httpRequest); } httpRequest = await this.AuthManagers["webRtc"].ApplyAsync(httpRequest).ConfigureAwait(false); // invoke request and get response. HttpStringResponse response = await this.GetClientInstance().ExecuteAsStringAsync(httpRequest, cancellationToken).ConfigureAwait(false); HttpContext context = new HttpContext(httpRequest, response); if (this.HttpCallBack != null) { this.HttpCallBack.OnAfterHttpResponseEventHandler(this.GetClientInstance(), response); } if (response.StatusCode == 400) { throw new ApiException("Bad Request", context); } if (response.StatusCode == 401) { throw new ApiException("Unauthorized", context); } if (response.StatusCode == 403) { throw new ApiException("Access Denied", context); } // [200,208] = HTTP OK if ((response.StatusCode < 200) || (response.StatusCode > 208)) { throw new ErrorException("Unexpected Error", context); } // handle errors defined at the API level. this.ValidateResponse(response, context); var result = ApiHelper.JsonDeserialize <Models.AccountsParticipantsResponse>(response.Body); ApiResponse <Models.AccountsParticipantsResponse> apiResponse = new ApiResponse <Models.AccountsParticipantsResponse>(response.StatusCode, response.Headers, result); return(apiResponse); }
/// <summary> /// Create a new participant under this account /// Participants are idempotent, so relevant parameters must be set in this function if desired /// </summary> /// <param name="accountId">Required parameter: Account ID</param> /// <param name="body">Optional parameter: Participant parameters</param> /// <return>Returns the ApiResponse<Models.AccountsParticipantsResponse> response from the API call</return> public ApiResponse <Models.AccountsParticipantsResponse> CreateParticipant(string accountId, Models.Participant body = null) { Task <ApiResponse <Models.AccountsParticipantsResponse> > t = CreateParticipantAsync(accountId, body); ApiHelper.RunTaskSynchronously(t); return(t.Result); }