public void delete(FreezeFile file) { if (file.container != null) { var conts = _containers .Where(x => x.accountID == file.container.accountID && x.id == file.container.id) ; foreach (var c in conts) { var fs = c.files.Where(x => x.fileID == file.fileID).ToList(); foreach (var f1 in fs) { c.files.Remove(f1); } } } var fs1 = _files .Where(x => x.fileID == file.fileID && (file.container != null ? x.container == null : x.container.id == file.container.id && x.container.accountID == file.container.accountID)) .ToList(); foreach (var f in fs1) { _files.Remove(f); } }
public void delete(FreezeFile file) { var fs1 = _db.Files .Where(x => x.fileID == file.fileID && (file.container != null ? string.IsNullOrWhiteSpace(x.containerID) : x.containerID == file.container.id && x.accountID == file.container.accountID)) .ToList(); if (fs1.Any()) { foreach (var f in fs1) { _db.Files.Remove(f); } _db.SaveChanges(); } }
public void add(FreezeFile ff) { FreezeFile oldf = null; if (ff.container == null) { oldf = _files .Where(x => (x.container == null) && ((!string.IsNullOrWhiteSpace(x.fileID) && x.fileID == ff.fileID) || (string.IsNullOrWhiteSpace(x.fileID) && x.path == ff.path) ) ) .FirstOrDefault(); } else { oldf = _files .Where(x => (x.container != null && (x.container == ff.container || (x.container.accountID == ff.container.accountID && x.container.id == ff.container.id)) ) && ((!string.IsNullOrWhiteSpace(x.fileID) && x.fileID == ff.fileID) || (string.IsNullOrWhiteSpace(x.fileID) && x.path == ff.path) ) ) .FirstOrDefault(); } if (oldf == null) { _files.Add(ff); } else { if (oldf.localHash != null && ff.localHash == null) { ff.localHash = oldf.localHash; } if (oldf.storedHash != null && ff.storedHash == null) { ff.storedHash = oldf.storedHash; } if (oldf.uploaded != DateTime.MinValue && ff.uploaded == DateTime.MinValue) { ff.uploaded = oldf.uploaded; } _files.Remove(oldf); _files.Add(ff); } if (ff.container != null) { var c = _containers.Where(x => x.accountID == ff.container.accountID && x.id == ff.container.id).FirstOrDefault(); if (c != null) { var f1 = c.files.Where(x => x.fileID == ff.fileID).FirstOrDefault(); if (f1 != null) { c.files.Remove(f1); } c.files.Add(ff); } } }
public void add(FreezeFile ff) { Models.ContFile oldf = null; if (ff.container == null) { oldf = _db.Files .Where(x => (!string.IsNullOrWhiteSpace(x.fileID) && x.fileID == ff.fileID) || (string.IsNullOrWhiteSpace(x.fileID) && x.path == ff.path) ) .FirstOrDefault(); } else { oldf = _db.Files .Where(x => (x.accountID == ff.container.accountID && x.containerID == ff.container.id) && ((!string.IsNullOrWhiteSpace(x.fileID) && x.fileID == ff.fileID) || (string.IsNullOrWhiteSpace(x.fileID) && x.path == ff.path) ) ) .FirstOrDefault(); } if (oldf == null) { oldf = new Models.ContFile(); if (ff.container != null) { oldf.accountID = ff.container.accountID; oldf.containerID = ff.container.id; } oldf.fileID = ff.fileID; oldf.path = ff.path; _db.Files.Add(oldf); } if (oldf.enchash != ff.enchash) { oldf.enchash = ff.enchash; } if (oldf.mimeType != ff.mimeType) { oldf.mimeType = ff.mimeType; } if (ff.modified != oldf.modified) { oldf.modified = ff.modified; } if (oldf.serviceInfo != ff.serviceInfo) { oldf.serviceInfo = ff.serviceInfo; } if (oldf.uploaded != ff.uploaded) { oldf.uploaded = ff.uploaded; } if (ff.localHash != null) { var h = _makeHashRec(ff.localHash); if (h != null && (oldf.localHashID == 0 || oldf.localHashID != h.id)) { oldf.localHashID = h.id; } } if (ff.storedHash != null) { var h = _makeHashRec(ff.storedHash); if (h != null && (oldf.storedHashID == 0 || oldf.storedHashID != h.id)) { oldf.storedHashID = h.id; } } _db.SaveChanges(); }