public async Task <IActionResult> PutAcRole([FromRoute] int id, [FromBody] AcRole acRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != acRole.RolId) { return(BadRequest()); } _context.Entry(acRole).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AcRoleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <MessageModel <AcRoleDto> > > AddUserInfo(AcRoleAddDto roleAddDto) { var res = new MessageModel <AcRoleDto>(); AcRole entity = _mapper.Map <AcRole>(roleAddDto); await _acRoleServices.AddEntityAsync(entity); res.Data = _mapper.Map <AcRoleDto>(entity); return(CreatedAtRoute(nameof(GetRoleById), new { id = entity.Id }, res.Data)); }
public async Task <IActionResult> PostAcRole([FromBody] AcRole acRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.AcRole.Add(acRole); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAcRole", new { id = acRole.RolId }, acRole)); }
public async Task <ActionResult <IEnumerable <AcRoleDto> > > GetRoleById(int id) { MessageModel <AcRoleDto> res = new MessageModel <AcRoleDto>(); if (!await _acRoleServices.ExistEntityAsync(a => a.Id == id)) { return(NotFound(StyleCode.NotFound(res))); } AcRole entity = await _acRoleServices.GetEntityByIdAsync(id); res.Data = _mapper.Map <AcRoleDto>(entity); return(Ok(res)); }
public MeetingPermissionId SetAcRole(ILmsLicense lmsCompany, LmsUserDTO u, bool ignoreEmptyACRole = false) { string role = u.LmsRole != null?u.LmsRole.ToLower() : string.Empty; var permission = MeetingPermissionId.view; u.AcRole = AcRole.Participant.Id; if (string.IsNullOrWhiteSpace(u.Id) || u.Id.Equals("0")) { permission = MeetingPermissionId.remove; u.AcRole = null; // "Remove"; // probably doesn't make sence, need to review and remove } LmsCompanyRoleMapping mapping = lmsCompany.RoleMappings.FirstOrDefault(x => x.LmsRoleName.Equals(role, StringComparison.OrdinalIgnoreCase)); if (mapping != null) { if (mapping.AcRole == AcRole.None.Id) { if (!ignoreEmptyACRole) { permission = AcRole.None.MeetingPermissionId; u.AcRole = AcRole.None.Id; } return(permission); } else { AcRole acRole = AcRole.GetById(mapping.AcRole); u.AcRole = acRole.Id; return(acRole.MeetingPermissionId); } } if (role.Contains("teacher") || role.Contains("instructor") || role.Contains("owner") || role.Contains("admin") || role.Contains("lecture")) { permission = MeetingPermissionId.host; u.AcRole = AcRole.Host.Id; } else if (role.Contains("ta") || role.Contains("designer") || role.Contains("author") || role.Contains("teaching assistant") || role.Contains("course builder") || role.Contains("grader") || role == "advisor") { u.AcRole = AcRole.Presenter.Id; permission = MeetingPermissionId.mini_host; } return(permission); }
public async Task <ActionResult <MessageModel <AcRoleDto> > > EditUserInfo(AcRoleEditDto roleEditDto) { MessageModel <AcRoleDto> res = new MessageModel <AcRoleDto>(); if (!await _acRoleServices.ExistEntityAsync(a => a.Id == roleEditDto.Id)) { return(NotFound(StyleCode.NotFound(res))); } AcRole entity = _mapper.Map <AcRole>(roleEditDto); await _acRoleServices.EditEntityAsync(entity); res.Data = _mapper.Map <AcRoleDto>(entity); return(Ok(res)); }
public virtual OperationResultWithData <LmsUserDTO> AddNewUser([FromBody] AddUserDto request) { try { // TODO: use FeatureName but this settings has true as default value if (!LmsCompany.GetSetting <bool>(LmsLicenseSettingNames.EnableAddGuest, true)) { return(OperationResultWithData <LmsUserDTO> .Error("Operation is not enabled.")); } var provider = GetAdminProvider(); Principal principal; try { if (string.IsNullOrWhiteSpace(request.PrincipalId)) { principal = CreatePrincipal(request, LmsCompany, provider); } else { principal = provider.GetOneByPrincipalId(request.PrincipalId).PrincipalInfo.Principal; } } catch (WarningMessageException ex) { return(OperationResultWithData <LmsUserDTO> .Error(ex.Message)); } // HACK: LmsMeetingType.Meeting param - not in use here LmsCourseMeeting meeting = MeetingSetup.GetCourseMeeting(LmsCompany, CourseId, request.MeetingId, LmsMeetingType.Meeting); // TODO: review for user-sync mode MeetingPermissionCollectionResult meetingEnrollments = provider.GetAllMeetingEnrollments(meeting.GetMeetingScoId()); if (meetingEnrollments.Status.Code != StatusCodes.ok) { string errorMessage = GetOutputErrorMessage( string.Format("AcUserController.AddNewUser.GetAllMeetingEnrollments. Status.Code: {0}, Status.SubCode: {1}.", meetingEnrollments.Status.Code, meetingEnrollments.Status.SubCode)); return(OperationResultWithData <LmsUserDTO> .Error(errorMessage)); } if (meetingEnrollments.Values.Any(x => x.PrincipalId == principal.PrincipalId)) { return(OperationResultWithData <LmsUserDTO> .Error(Messages.UserIsAlreadyParticipant)); } AcRole role = AcRole.GetById(request.MeetingRole); StatusInfo status = provider.UpdateScoPermissionForPrincipal(meeting.GetMeetingScoId(), principal.PrincipalId, role.MeetingPermissionId); // Add user as guest to DB var guest = new LmsCourseMeetingGuest { PrincipalId = principal.PrincipalId, LmsCourseMeeting = meeting, }; meeting.MeetingGuests.Add(guest); this.LmsCourseMeetingModel.RegisterSave(meeting, flush: true); var result = new LmsUserDTO { GuestId = guest.Id, AcId = guest.PrincipalId, Name = principal.Name, AcRole = request.MeetingRole, }; return(result.ToSuccessResult()); } catch (Exception ex) { string errorMessage = GetOutputErrorMessage("AcUserController.AddNewUser", ex); return(OperationResultWithData <LmsUserDTO> .Error(errorMessage)); } }