public async Task <ActionResult <GroupInfo> > UpdateGroup(int groupId, [FromBody] UpdateGroupParameters parameters) { var group = await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false); var newName = parameters.Name ?? group.Name; var newIsManualCheckingEnabled = parameters.IsManualCheckingEnabled ?? group.IsManualCheckingEnabled; var newIsManualCheckingEnabledForOldSolutions = parameters.IsManualCheckingEnabledForOldSolutions ?? group.IsManualCheckingEnabledForOldSolutions; var newDefaultProhibitFurtherReview = parameters.DefaultProhibitFurtherReview ?? group.DefaultProhibitFutherReview; var newCanUsersSeeGroupProgress = parameters.CanStudentsSeeGroupProgress ?? group.CanUsersSeeGroupProgress; await groupsRepo.ModifyGroupAsync( groupId, newName, newIsManualCheckingEnabled, newIsManualCheckingEnabledForOldSolutions, newDefaultProhibitFurtherReview, newCanUsersSeeGroupProgress ).ConfigureAwait(false); if (parameters.IsArchived.HasValue) { await groupsRepo.ArchiveGroupAsync(groupId, parameters.IsArchived.Value).ConfigureAwait(false); } if (parameters.IsInviteLinkEnabled.HasValue) { await groupsRepo.EnableInviteLinkAsync(groupId, parameters.IsInviteLinkEnabled.Value).ConfigureAwait(false); } return(BuildGroupInfo(await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false))); }
public async Task <IHttpActionResult> Update(UpdateGroupParameters existingGroup) { // validate if (existingGroup == null) { return(BadRequest()); //throw new ArgumentNullException(nameof(groupInfo)); } using (var db = new ZapContext()) { var user = await GetCurrentUser(db).ConfigureAwait(true); var group = await db.Groups .Where(g => g.GroupId == existingGroup.GroupId) .Include(gr => gr.Administrators) .FirstOrDefaultAsync().ConfigureAwait(true); if (group == null) { return(BadRequest(Properties.Resources.ErrorGroupNotFound)); } if (!group.Administrators.Select(a => a.AppId).Contains(user.AppId)) { return(Unauthorized()); } var cleanName = existingGroup.GroupName.CleanUnicode().SanitizeXSS(); bool exists = await GroupExists(cleanName, existingGroup.GroupId, db).ConfigureAwait(true); if (exists) { return(BadRequest(Properties.Resources.ErrorGroupDuplicate)); } // Make updates var icon = await GetGroupIcon(existingGroup.ImageId, db).ConfigureAwait(true); if (icon == null) { return(BadRequest(Properties.Resources.ErrorIconNotFound)); } group.DefaultLanguage = existingGroup.Language == null ? "en" : existingGroup.Language; // Ensure value group.Tags = existingGroup.Tags.CleanUnicode().SanitizeXSS(); group.GroupName = cleanName; group.GroupImage = icon; await db.SaveChangesAsync().ConfigureAwait(true); return(Ok(new AddGroupResponse() { success = true, GroupId = group.GroupId })); } }
public async Task <ActionResult <GroupInfo> > UpdateGroup(int groupId, [FromBody] UpdateGroupParameters parameters) { var hasEditAccess = await groupAccessesRepo.HasUserEditAccessToGroupAsync(groupId, UserId).ConfigureAwait(false); if (!hasEditAccess) { return(StatusCode((int)HttpStatusCode.Forbidden, new ErrorResponse("You have no edit access to this group"))); } var group = await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false); var newName = parameters.Name ?? group.Name; var newIsManualCheckingEnabled = parameters.IsManualCheckingEnabled ?? group.IsManualCheckingEnabled; var newIsManualCheckingEnabledForOldSolutions = parameters.IsManualCheckingEnabledForOldSolutions ?? group.IsManualCheckingEnabledForOldSolutions; var newDefaultProhibitFurtherReview = parameters.DefaultProhibitFurtherReview ?? group.DefaultProhibitFutherReview; var newCanUsersSeeGroupProgress = parameters.CanStudentsSeeGroupProgress ?? group.CanUsersSeeGroupProgress; await groupsRepo.ModifyGroupAsync( groupId, newName, newIsManualCheckingEnabled, newIsManualCheckingEnabledForOldSolutions, newDefaultProhibitFurtherReview, newCanUsersSeeGroupProgress ).ConfigureAwait(false); if (parameters.IsArchived.HasValue) { await groupsRepo.ArchiveGroupAsync(groupId, parameters.IsArchived.Value).ConfigureAwait(false); if (parameters.IsArchived.Value) { var notification = new GroupIsArchivedNotification { GroupId = groupId }; await notificationsRepo.AddNotification(group.CourseId, notification, UserId); await ArchiveAllOldGroups(); } } if (parameters.IsInviteLinkEnabled.HasValue) { await groupsRepo.EnableInviteLinkAsync(groupId, parameters.IsInviteLinkEnabled.Value).ConfigureAwait(false); } return(BuildGroupInfo(await groupsRepo.FindGroupByIdAsync(groupId).ConfigureAwait(false))); }