/// <summary> /// Make User active or inactive. /// </summary> /// <param name="UserGuid">User Unique Identifier.</param> /// <param name="Status">Status.</param> /// <returns></returns> public async Task <DataResponse <UpdateUserStatusResult> > UpdateUserStatus(string UserGuid, bool Status) { try { if (string.IsNullOrEmpty(UserGuid)) { List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>(); ErrorItemModel errorItemModel = new ErrorItemModel() { Message = "UserGuid is required", Param = "UserGuid" }; errorItemModels.Add(errorItemModel); return(new DataResponse <UpdateUserStatusResult>(null) { errorMessages = errorItemModels, status = false }); } UpdateUserStatusModel request = new UpdateUserStatusModel { isActive = Status }; var portalApi = await _ioTConnectAPIDiscovery.GetPortalUrl(_envCode, _solutionKey, IoTConnectBaseURLType.UserBaseUrl); string accessTokenUrl = string.Concat(portalApi, UserApi.UpdateStatus); string formattedUrl = String.Format(accessTokenUrl, Constants.userVersion, UserGuid); var result = await formattedUrl.WithHeaders(new { Content_type = Constants.contentType, Authorization = Constants.bearerTokenType + _token }) .PutJsonAsync(request).ReceiveJson <DataResponse <List <UpdateUserStatusResult> > >(); return(new DataResponse <UpdateUserStatusResult>(null) { data = result.data.FirstOrDefault(), message = result.message, status = true }); } catch (IoTConnectException ex) { List <ErrorItemModel> errorItemModels = new List <ErrorItemModel>(); errorItemModels.AddRange(ex.error); return(new DataResponse <UpdateUserStatusResult>(null) { errorMessages = errorItemModels, message = ex.message, status = false }); } catch (Exception ex) { await _ioTConnectAPIDiscovery.LoggedException(_envCode, ex, "User", "UpdateUserStatus()"); throw ex; } }
public async Task <IActionResult> Update(UpdateUserStatusModel input) { var userId = this.User .FindFirstValue(ClaimTypes.NameIdentifier); var course = this.courseUserService .FindCourseUser(input.CourseId, input.UserId); if (course == null || course.UserStatus == null || course.UserStatus == input.Status) { return(this.BadRequest()); } var result = await this.courseUserService .UpdateStatusAsync <CourseUserModel>(input.CourseId, input.UserId, input.Status); if (result == null) { return(this.StatusCode(500)); } var user = await this.userManager.FindByIdAsync(input.UserId); if (result.Status == "Accepted") { await this.userManager.AddClaimAsync(user, new Claim(CourseRoleName.Member, course.Id)); } else { var claim = user.Claims.FirstOrDefault(x => x.ClaimType == CourseRoleName.Member && x.ClaimValue == course.Id); user.Claims.Remove(claim); } result.Date = TimeSpanParser.Parse((DateTime)(result.ModifiedOn ?? result.CreatedOn)); return(this.Ok(result)); }