/// <summary> /// Uploads file to azure. /// </summary> /// <param name="fileDetails">Details of the file.</param> public OperationStatus UploadAsset(FileDetail fileDetails) { OperationStatus operationStatus = null; this.CheckNotNull(() => new { fileDetails }); var fileBlob = new BlobDetails() { BlobID = fileDetails.Name, Data = fileDetails.DataStream, MimeType = fileDetails.MimeType }; try { if (_blobDataRepository.UploadAsset(fileBlob)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return(operationStatus); }
public OperationStatus ReportOffensiveCommunity(ReportEntityDetails offensiveCommunityDetails) { OperationStatus status = null; this.CheckNotNull(() => new { reportEntityDetails = offensiveCommunityDetails }); try { var offensiveCommunity = new OffensiveCommunities(); Mapper.Map(offensiveCommunityDetails, offensiveCommunity); offensiveCommunity.ReportedDatetime = DateTime.UtcNow; _offensiveCommunitiesRepository.Add(offensiveCommunity); _offensiveCommunitiesRepository.SaveChanges(); } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } // Status will be null if all sub communities and contents have been deleted. // If one them is not deleted then the status will have the exception details. status = status ?? OperationStatus.CreateSuccessStatus(); return(status); }
/// <summary> /// Updates the all the entries for the given Content with all the details. /// </summary> /// <param name="contentId">Content ID.</param> /// <param name="details">Details provided.</param> /// <returns>True if content was updated; otherwise false.</returns> private OperationStatus UpdateAllOffensiveContentEntry(long contentId, OffensiveEntry details) { OperationStatus status = null; try { var offensiveContents = _offensiveContentRepository.GetItems(oc => oc.ContentID == contentId && oc.OffensiveStatusID == (int)OffensiveStatusType.Flagged, null, false); if (offensiveContents != null && offensiveContents.Any()) { foreach (var item in offensiveContents) { item.OffensiveStatusID = (int)details.Status; item.Justification = details.Justification; item.ReviewerID = details.ReviewerID; item.ReviewerDatetime = DateTime.UtcNow; _offensiveContentRepository.Update(item); } } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } // Status will be null if all sub communities and contents have been deleted. // If one them is not deleted then the status will have the exception details. status = status ?? OperationStatus.CreateSuccessStatus(); return(status); }
/// <summary> /// Move Home video from temp to correct container. /// </summary> /// <param name="fileDetails">Details of the video.</param> public OperationStatus MoveTempFile(FileDetail fileDetails) { OperationStatus operationStatus = null; this.CheckNotNull(() => new { fileDetails }); // Move Home video. if (fileDetails.AzureID != null) { // Move the video file from temporary container to file container. try { if (MoveAssetFile(fileDetails)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } return(operationStatus); }
public OperationStatus UpdateStaticContent(StaticContentDetails staticContentDetails) { OperationStatus status = null; try { Expression <Func <StaticContent, bool> > condition = content => content.TypeID == (int)staticContentDetails.TypeID && content.IsDeleted == false; var contentValue = _staticContentRepository.GetItem(condition); if (contentValue != null) { contentValue.Content = staticContentDetails.Content; contentValue.ModifiedByID = staticContentDetails.ModifiedByID; contentValue.ModifiedDatetime = DateTime.UtcNow; _staticContentRepository.Update(contentValue); _staticContentRepository.SaveChanges(); } else { status = OperationStatus.CreateFailureStatus(string.Format(CultureInfo.CurrentCulture, Resources.StaticContentTypeNotFound, staticContentDetails.TypeID)); } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } status = status ?? OperationStatus.CreateSuccessStatus(); return(status); }
/// <summary> /// Checks the file from azure which is identified by file name. /// </summary> /// <param name="fileName"> /// file name. /// </param> /// <returns> /// Operation Status /// </returns> public OperationStatus CheckIfAssetExists(string fileName) { OperationStatus operationStatus = null; var fileBlob = new BlobDetails() { BlobID = fileName, }; try { if (_blobDataRepository.CheckIfAssetExists(fileBlob)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } catch (Exception ex) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage, ex); } return(operationStatus); }
/// <summary> /// Uploads the associated file to temporary container. /// </summary> /// <param name="fileDetail">Details of the associated file.</param> /// <returns>True if content is uploaded; otherwise false.</returns> public OperationStatus UploadTemporaryFile(FileDetail fileDetail) { OperationStatus operationStatus = null; // Make sure file detail is not null this.CheckNotNull(() => new { fileDetail }); var fileBlob = new BlobDetails() { BlobID = fileDetail.AzureID.ToString(), Data = fileDetail.DataStream, MimeType = fileDetail.MimeType }; try { _blobDataRepository.UploadTemporaryFile(fileBlob); operationStatus = OperationStatus.CreateSuccessStatus(); } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return(operationStatus); }
public Task <OperationStatus> UpdateFeaturedCommunities(IEnumerable <AdminEntityDetails> communities, long userId, int?categoryId) { OperationStatus status = null; try { // TODO: To find a better way of updating and deleting the featured communities. if (_userRepository.IsSiteAdmin(userId)) { IEnumerable <FeaturedCommunities> results; if (categoryId.HasValue) { results = _featuredCommunitiesRepository.GetItems(fc => fc.CategoryID == categoryId, null, false); } else { results = _featuredCommunitiesRepository.GetItems(fc => int.Equals(fc.CategoryID, categoryId), null, false); } if (results != null && results.Any()) { foreach (var item in results) { _featuredCommunitiesRepository.Delete(item); } } if (communities != null && communities.Any()) { foreach (var item in communities) { var community = new FeaturedCommunities() { CategoryID = categoryId, CommunityID = item.EntityID, SortOrder = item.SortOrder, UpdatedByID = userId, UpdatedDatetime = DateTime.UtcNow }; _featuredCommunitiesRepository.Add(community); } } _featuredCommunitiesRepository.SaveChanges(); } else { status = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError); } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } status = status ?? OperationStatus.CreateSuccessStatus(); return(Task.FromResult(status)); }
/// <summary> /// Joins the current user to community for which the invite request token was generated. /// </summary> /// <param name="userId">User who is making the join request</param> /// <param name="inviteRequestToken">Token to be used for joining the community</param> /// <returns>Status of the operation. Success, if succeeded, failure message and exception details in case of exception.</returns> public Task <OperationStatus> JoinCommunity(long userId, Guid inviteRequestToken) { var operationStatus = new OperationStatus(); try { // Find the invite request entity in database. var inviteRequest = _inviteRequestRepository.GetItem(invite => invite.InviteRequestToken == inviteRequestToken, "InviteRequestContent"); if (inviteRequest == null || inviteRequest.IsDeleted == true) { operationStatus = OperationStatus.CreateFailureStatus(Resources.InviteDeletedErrorMessage); } else if (inviteRequest.Used == true) { operationStatus = OperationStatus.CreateFailureStatus(Resources.InviteUsedErrorMessage); } else { var permissionItem = new PermissionItem { UserID = userId, CommunityID = inviteRequest.InviteRequestContent.CommunityID, Role = (UserRole)inviteRequest.InviteRequestContent.RoleID }; // Check if at all the user is already member of the same community. var existingRole = _userCommunitiesRepository.GetItem( userCommunity => userCommunity.UserID == userId && userCommunity.CommunityId == inviteRequest.InviteRequestContent.CommunityID); if (existingRole == null || inviteRequest.InviteRequestContent.RoleID > existingRole.RoleID) { operationStatus = _userCommunitiesRepository.UpdateUserRoles(permissionItem); } else { // Just mark OperationStatus as succeeded so that, the token will be marked as used. operationStatus.Succeeded = true; } if (operationStatus.Succeeded) { inviteRequest.Used = true; inviteRequest.UsedByID = userId; inviteRequest.UsedDate = DateTime.UtcNow; _inviteRequestRepository.Update(inviteRequest); _inviteRequestRepository.SaveChanges(); } } } catch (Exception) { // TODO: Add exception handling logic here. operationStatus.Succeeded = false; operationStatus.CustomErrorMessage = true; operationStatus.ErrorMessage = Resources.UnknownErrorMessage; } return(Task.FromResult(operationStatus)); }
private OperationStatus DeleteContentRecursively(long contentId, long profileId, bool isOffensive, OffensiveEntry offensiveDetails) { OperationStatus status = null; try { // Get the current content from DB. var content = _contentRepository.GetItem((c) => c.ContentID == contentId && c.IsDeleted == false); if (content != null) { var userRole = GetContentUserRole(content, profileId); if (CanEditDeleteContent(content, profileId, userRole)) { content.IsDeleted = true; content.IsOffensive = isOffensive; content.DeletedByID = profileId; content.DeletedDatetime = DateTime.UtcNow; // Update all the offensive entity entries if the content is being deleted. UpdateAllOffensiveContentEntry(content.ContentID, offensiveDetails); foreach (var contentRelation in content.ContentRelation) { contentRelation.Content1.IsDeleted = true; contentRelation.Content1.IsOffensive = isOffensive; contentRelation.Content1.DeletedByID = profileId; contentRelation.Content1.DeletedDatetime = DateTime.UtcNow; } _contentRepository.Update(content); // Save changes to the database _contentRepository.SaveChanges(); status = OperationStatus.CreateSuccessStatus(); } else { // In case if user is reader or visitor, he should not be allowed to delete the content. status = OperationStatus.CreateFailureStatus("User does not have permission for deleting the content."); } } else { status = OperationStatus.CreateFailureStatus(string.Format(CultureInfo.CurrentCulture, "Content with ID '{0}' was not found", contentId)); } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } return(status); }
public Task <OperationStatus> PromoteAsSiteAdmin(IEnumerable <long> adminUsers, long updatedById) { OperationStatus operationStatus = null; try { if (_userRepository.IsSiteAdmin(updatedById)) { var userTypes = _userTypeRepository.GetAll(null); // Mark the user who have been demoted from the site administrators as Regular user's. Expression <Func <User, bool> > removedUserCondition = (user) => (user.UserID != updatedById && user.UserTypeID == (int)UserTypes.SiteAdmin && !adminUsers.Contains(user.UserID)); var removedAdmins = _userRepository.GetItems(removedUserCondition, null, false); IEnumerable <UserType> userTypesEnumerable = userTypes as UserType[] ?? userTypes.ToArray(); foreach (var removedUser in removedAdmins) { removedUser.UserType = userTypesEnumerable.FirstOrDefault(type => type.UserTypeID == (int)UserTypes.Regular); _userRepository.Update(removedUser); } // Mark the user who have been promoted as site administrators. Expression <Func <User, bool> > promotedUserCondition = (user) => (user.UserID != updatedById && adminUsers.Contains(user.UserID) && user.UserTypeID != (int)UserTypes.SiteAdmin); var promotedAdmins = _userRepository.GetItems(promotedUserCondition, null, false); foreach (var promotedUser in promotedAdmins) { promotedUser.UserType = userTypesEnumerable.FirstOrDefault(type => type.UserTypeID == (int)UserTypes.SiteAdmin); _userRepository.Update(promotedUser); } _userRepository.SaveChanges(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError); } } catch (Exception exception) { operationStatus = OperationStatus.CreateFailureStatus(exception); } operationStatus = operationStatus ?? OperationStatus.CreateSuccessStatus(); return(Task.FromResult(operationStatus)); }
public Task <OperationStatus> UpdateAllOffensiveContentEntry(OffensiveEntry details) { this.CheckNotNull(() => new { details = details }); OperationStatus status = null; try { if (_userRepository.IsSiteAdmin(details.ReviewerID)) { var offensiveContents = _offensiveContentRepository.GetItems(oc => oc.ContentID == details.EntityID && oc.OffensiveStatusID == (int)OffensiveStatusType.Flagged, null, false); if (offensiveContents != null && offensiveContents.Any()) { foreach (var item in offensiveContents) { item.OffensiveStatusID = (int)details.Status; item.Justification = details.Justification; item.ReviewerID = details.ReviewerID; item.ReviewerDatetime = DateTime.UtcNow; _offensiveContentRepository.Update(item); } _offensiveContentRepository.SaveChanges(); } } else { status = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError); } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } // Status will be null if all sub communities and contents have been deleted. // If one them is not deleted then the status will have the exception details. status = status ?? OperationStatus.CreateSuccessStatus(); return(Task.FromResult(status)); }
/// <summary> /// Deletes the file from azure which is identified by file name. /// </summary> /// <param name="fileName"> /// file name. /// </param> /// <returns> /// Operation Status /// </returns> public OperationStatus DeleteAsset(string fileName) { OperationStatus operationStatus = null; var fileBlob = new BlobDetails() { BlobID = fileName, }; try { _blobDataRepository.DeleteAsset(fileBlob); operationStatus = OperationStatus.CreateSuccessStatus(); } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return(operationStatus); }
/// <summary> /// Sets the given access type for the specified Content. /// </summary> /// <param name="contentId">Content Id</param> /// <param name="userId">User Identity</param> /// <param name="accessType">Access type of the Content.</param> /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns> public OperationStatus SetContentAccessType(long contentId, long userId, AccessType accessType) { OperationStatus status = null; try { if (_userRepository.IsSiteAdmin(userId)) { // Get the current content from DB. var content = _contentRepository.GetItem((c) => c.ContentID == contentId); // Make sure content exists this.CheckNotNull(() => new { content }); content.AccessTypeID = (int)accessType; content.IsOffensive = (accessType == AccessType.Private); var offensiveDetails = new OffensiveEntry() { EntityID = contentId, ReviewerID = userId, Status = OffensiveStatusType.Offensive }; UpdateAllOffensiveContentEntry(contentId, offensiveDetails); _contentRepository.Update(content); _contentRepository.SaveChanges(); // Create Success message if set access type is successful. status = OperationStatus.CreateSuccessStatus(); } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } return(status); }
public OperationStatus UpdateOffensiveContentEntry(OffensiveEntry details) { this.CheckNotNull(() => new { details = details }); OperationStatus status = null; try { if (_userRepository.IsSiteAdmin(details.ReviewerID)) { var offensiveContents = _offensiveContentRepository.GetItem(oc => oc.OffensiveContentID == details.EntryID); if (offensiveContents != null) { offensiveContents.OffensiveStatusID = (int)details.Status; offensiveContents.Justification = details.Justification; offensiveContents.ReviewerID = details.ReviewerID; offensiveContents.ReviewerDatetime = DateTime.UtcNow; _offensiveContentRepository.Update(offensiveContents); _offensiveContentRepository.SaveChanges(); } } else { status = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError); } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } // Status will be null if all sub communities and contents have been deleted. // If one them is not deleted then the status will have the exception details. status = status ?? OperationStatus.CreateSuccessStatus(); return(status); }
/// <summary> /// Checks if the user is Site Admin /// </summary> /// <param name="userId">ID of the user.</param> /// <returns>True if user is site admin;Otherwise false.</returns> public OperationStatus IsSiteAdmin(long userId) { OperationStatus operationStatus = null; try { if (_userRepository.IsSiteAdmin(userId)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError); } } catch (Exception exception) { operationStatus = OperationStatus.CreateFailureStatus(exception); } return(operationStatus); }
/// <summary> /// Removes the specified invite request. /// </summary> /// <param name="userId">User who is removing the invite request</param> /// <param name="inviteRequestId">Invite request to be removed</param> /// <returns>True if the invite request is removed, false otherwise</returns> public Task <OperationStatus> RemoveInviteRequest(long userId, int inviteRequestId) { var operationStatus = new OperationStatus(); try { // Find the invite request entity in database. InviteRequest inviteRequest = _inviteRequestRepository.GetItem(ir => ir.InviteRequestID == inviteRequestId, "InviteRequestContent"); // Check invite request is not null this.CheckNotNull(() => new { inviteRequest }); var userRole = _userRepository.GetUserRole(userId, inviteRequest.InviteRequestContent.CommunityID); if (userRole >= UserRole.Moderator) { inviteRequest.IsDeleted = true; inviteRequest.DeletedByID = userId; inviteRequest.DeletedDate = DateTime.UtcNow; _inviteRequestRepository.Update(inviteRequest); _inviteRequestRepository.SaveChanges(); operationStatus.Succeeded = true; } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.NoPermissionInviteRequestMessage); } } catch (Exception) { // TODO: Add exception handling logic here. operationStatus.Succeeded = false; operationStatus.CustomErrorMessage = true; operationStatus.ErrorMessage = Resources.UnknownErrorMessage; } return(Task.FromResult(operationStatus)); }
/// <summary> /// Un-deletes the specified content from the Earth database so that it is again accessible in the site. /// </summary> /// <param name="contentId">Content Id</param> /// <param name="userId">User Identity</param> /// <returns>Status of the operation. Success, if succeeded. Failure message and exception details in case of exception.</returns> public OperationStatus UnDeleteOffensiveContent(long contentId, long userId) { OperationStatus status = null; try { if (_userRepository.IsSiteAdmin(userId)) { // Get the current content from DB. var content = _contentRepository.GetItem((c) => c.ContentID == contentId); if (content != null) { content.IsDeleted = false; // We need to mark the community as not offensive as the Admin is marking the content as undeleted. content.IsOffensive = false; // We need to mark the DeletedBy as null as we are Undoing the delete operation. // Also DeleteBy filed will be used to check if the user has explicitly deleted the content. content.User2 = null; var parentCommunity = Enumerable.ElementAt(content.CommunityContents, 0).Community; if ((parentCommunity.CommunityTypeID == (int)CommunityTypes.Community || parentCommunity.CommunityTypeID == (int)CommunityTypes.Folder) && parentCommunity.IsDeleted == true) { // Get the "None" (User) community of the user who uploaded the Content. var noneCommunity = _communityRepository.GetItem( c => c.CreatedByID == content.CreatedByID && c.CommunityTypeID == (int)CommunityTypes.User); this.CheckNotNull(() => new { noneCommunity }); // Remove the existing relation content.CommunityContents.Remove(Enumerable.ElementAt(content.CommunityContents, 0)); // Set the None community as parent community. var noneCommunityContent = new CommunityContents() { CommunityID = noneCommunity.CommunityID, Content = content }; content.CommunityContents.Add(noneCommunityContent); } foreach (var contentRelation in content.ContentRelation) { contentRelation.Content1.IsDeleted = false; contentRelation.Content1.User2 = null; } _contentRepository.Update(content); // Save changes to the database _contentRepository.SaveChanges(); status = OperationStatus.CreateSuccessStatus(); } else { status = OperationStatus.CreateFailureStatus(string.Format(CultureInfo.CurrentCulture, "Content with ID '{0}' was not found", contentId)); } } else { status = OperationStatus.CreateFailureStatus(Resources.UserNotSiteAdminError); } } catch (Exception exception) { status = OperationStatus.CreateFailureStatus(exception); } return(status); }