internal string AddSharedFile(IFormFile file) { var expiredFiles = RemotelyContext.SharedFiles.Where(x => DateTime.Now - x.Timestamp > TimeSpan.FromDays(7)); foreach (var expiredFile in expiredFiles) { RemotelyContext.Remove(expiredFile); } byte[] fileContents; using (var stream = file.OpenReadStream()) { using (var ms = new MemoryStream()) { stream.CopyTo(ms); fileContents = ms.ToArray(); } } var newEntity = RemotelyContext.Add(new SharedFile() { FileContents = fileContents, FileName = file.FileName, ContentType = file.ContentType }); RemotelyContext.SaveChanges(); return(newEntity.Entity.ID); }
internal void CleanupOldRecords() { if (AppConfig.DataRetentionInDays > 0) { RemotelyContext.EventLogs .Where(x => DateTime.Now - x.TimeStamp > TimeSpan.FromDays(AppConfig.DataRetentionInDays)) .ForEachAsync(x => { RemotelyContext.Remove(x); }).Wait(); RemotelyContext.CommandContexts .Where(x => DateTime.Now - x.TimeStamp > TimeSpan.FromDays(AppConfig.DataRetentionInDays)) .ForEachAsync(x => { RemotelyContext.Remove(x); }).Wait(); RemotelyContext.Devices .Where(x => DateTime.Now - x.LastOnline > TimeSpan.FromDays(AppConfig.DataRetentionInDays)) .ForEachAsync(x => { RemotelyContext.Remove(x); }).Wait(); } }
internal void DeleteInvite(string requesterUserName, string inviteID) { var requester = RemotelyContext.Users .Include(x => x.Organization) .ThenInclude(x => x.InviteLinks) .FirstOrDefault(x => x.UserName == requesterUserName); var invite = requester.Organization.InviteLinks.FirstOrDefault(x => x.ID == inviteID); RemotelyContext.Remove(invite); RemotelyContext.SaveChanges(); }
public void DeleteInvite(string orgID, string inviteID) { var invite = RemotelyContext.InviteLinks.FirstOrDefault(x => x.OrganizationID == orgID && x.ID == inviteID); var user = RemotelyContext.Users.FirstOrDefault(x => x.UserName == invite.InvitedUser); if (user != null && string.IsNullOrWhiteSpace(user.PasswordHash)) { RemotelyContext.Remove(user); } RemotelyContext.Remove(invite); RemotelyContext.SaveChanges(); }
public void CleanupEmptyOrganizations() { var emptyOrgs = RemotelyContext.Organizations .Include(x => x.RemotelyUsers) .Include(x => x.CommandContexts) .Include(x => x.InviteLinks) .Include(x => x.Devices) .Include(x => x.SharedFiles) .Include(x => x.PermissionGroups) .Include(x => x.EventLogs) .Where(x => x.RemotelyUsers.Count == 0); foreach (var emptyOrg in emptyOrgs) { RemotelyContext.Remove(emptyOrg); } RemotelyContext.SaveChanges(); }