public async Task <StatusCode <ShareEveryoneOut> > ShareForEveryone(Guid resourceId, string username, string password, DateTime?expirationDateTime, int?downloadLimit) { string userId = (await _databaseContext.Users.FirstOrDefaultAsync(_ => _.UserName == username))?.Id; ResourceAbstract resourceAbstract = await _databaseContext.ResourceAbstracts.FirstOrDefaultAsync(_ => _.ID == resourceId && _.OwnerID == userId); if (resourceAbstract == null) { return(new StatusCode <ShareEveryoneOut>(StatusCodes.Status404NotFound, StatusMessages.FILE_NOT_FOUND)); } ShareEveryone shareEveryone = await _databaseContext.ShareEveryones.FirstOrDefaultAsync(_ => _.ResourceID == resourceId && _.OwnerID == userId); if (shareEveryone == null) { shareEveryone = new ShareEveryone { CreatedDateTime = DateTime.Now, DownloadLimit = downloadLimit, ExpirationDateTime = expirationDateTime, ResourceID = resourceId, OwnerID = userId, Password = password, Token = GenerateToken() }; await _databaseContext.ShareEveryones.AddAsync(shareEveryone); resourceAbstract.IsShared = true; resourceAbstract.IsSharedForEveryone = true; } else { shareEveryone.DownloadLimit = downloadLimit; shareEveryone.ExpirationDateTime = expirationDateTime; shareEveryone.Password = password; shareEveryone.LastModifiedDateTime = DateTime.Now; } if (shareEveryone.ExpirationDateTime.HasValue) { shareEveryone.ExpirationDateTime = shareEveryone.ExpirationDateTime.Value.AddHours(1); } await _databaseContext.SaveChangesAsync(); ShareEveryoneOut result = _mapper.Map <ShareEveryoneOut>(shareEveryone); return(new StatusCode <ShareEveryoneOut>(StatusCodes.Status200OK, result)); }
public async Task <StatusCode <ShareEveryoneOut> > GetShareForEveryoneByFileIdAndUser(Guid resourceId, string username) { string userId = (await _databaseContext.Users .FirstOrDefaultAsync(_ => _.UserName == username)) ?.Id; ShareEveryone shareEveryone = await _databaseContext.ShareEveryones .FirstOrDefaultAsync(_ => _.ResourceID == resourceId && _.OwnerID == userId); if (shareEveryone == null) { return(new StatusCode <ShareEveryoneOut>(StatusCodes.Status404NotFound, StatusMessages.FILE_IS_NOT_SHARED)); } ShareEveryoneOut result = _mapper.Map <ShareEveryoneOut>(shareEveryone); return(new StatusCode <ShareEveryoneOut>(StatusCodes.Status200OK, result)); }
public async Task <StatusCode <ShareEveryoneOut> > GetShareForEveryoneByTokenAndPassword(string token, string password) { ShareEveryone shareEveryone = await _databaseContext.ShareEveryones .Include(_ => _.Owner) .Include(_ => _.Resource) .FirstOrDefaultAsync(_ => _.Token == token); if (shareEveryone == null) { return(new StatusCode <ShareEveryoneOut>(StatusCodes.Status404NotFound, StatusMessages.TOKEN_NOT_FOUND)); } if (shareEveryone.Password != password) { return(new StatusCode <ShareEveryoneOut>(StatusCodes.Status401Unauthorized, StatusMessages.PASSWORD_IS_WRONG)); } ShareEveryoneOut shareEveryoneOut = _mapper.Map <ShareEveryoneOut>(shareEveryone); return(new StatusCode <ShareEveryoneOut>(StatusCodes.Status200OK, shareEveryoneOut)); }