public bool AddFile(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { m.Directories = GetDirList(c, m); f.Dir = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); if (!CheckFileExistence(c, m, d, f)) { AddFileContent(f); //TypeManipulator.TypeToId(f); File f1 = File.CreateFile(1, f.Dir, 1, f.Content, f.Name, f.Size, f.Hash, f.Uploaded, f.Modified); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { context.Files.AddObject(f1); context.SaveChanges(); } } else { GetFileId(c, m, d, f); GetFileContentId(c, m, d, f); UpdateFileContent(f); //TypeManipulator.TypeToId(f); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { File f1 = (from o in context.Files where o.file_id == f.Id select o).Single(); f1.file_hash = f.Hash; f1.file_modified = f.Modified; f1.file_size = f.Size; f1.file_uploaded = f.Uploaded; context.SaveChanges(); } } return true; }
public bool AddMachine(Credentials c, MachineContents m) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (MachineNameExists(context, m.Name)) { //throw new Exception("machine with given name already exists"); return false; } else { int user_id = LoginToId(context, c.Login); Machine m1 = Machine.CreateMachine(1, user_id, m.Name); m1.machine_description = m.Description; context.Machines.AddObject(m1); context.SaveChanges(); } } return true; }
public bool AddUser(UserContents u) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (LoginExists(context, u.Login)) { //throw new Exception("user already exists"); return false; } else { //TODO: don't use password directly User u1 = User.CreateUser(1, u.Login, u.Password); u1.user_email = u.Email; u1.user_fullname = u.Name; u1.user_lastlogin = DateTime.Now; context.Users.AddObject(u1); context.SaveChanges(); } } return true; }
private void UpdateLastLogin(filesyncEntitiesNew context, int id) { //try { var u1 = (from o in context.Users where o.user_id == id select o).SingleOrDefault(); if (u1 != null) { u1.user_lastlogin = DateTime.Now; context.SaveChanges(); } //} catch (Exception ex) { // throw new Exception("no such user", ex); //} }
private void AddFileContent(FileContents f) { int AddedContentId; Content f1 = Content.CreateContent(1, f.Data); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { context.Contents.AddObject(f1); context.SaveChanges(); AddedContentId = (from c in context.Contents select c).ToList().Last().content_id; } f.Content = AddedContentId; }
private static void UpdateFileContent(FileContents f) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { Content c1 = (from o in context.Contents where o.content_id == f.Content select o).Single(); c1.content_data = f.Data; context.SaveChanges(); } }
private static void AddMachDir(MachineContents m, DirectoryContents d) { MachineDir md1 = MachineDir.CreateMachineDir(m.Id, d.Id, d.LocalPath); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { context.MachineDirs.AddObject(md1); context.SaveChanges(); } }
private static void AddDir(DirectoryContents d) { int AddedDirId; Dir d1 = Dir.CreateDir(1, d.Name, d.Owner); d1.dir_description = d.Description; using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { context.Dirs.AddObject(d1); context.SaveChanges(); AddedDirId = (from z in context.Dirs select z).ToList().Last().dir_id; } d.Id = AddedDirId; }
public bool DelUser(Credentials c) { UserContents u =(UserContents) GetUser(c); bool result = false; using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (!Authenticate(context, c)) return result; int id = LoginToId(context, u.Login); var u1 = (from o in context.Users where o.user_id == id select o).SingleOrDefault(); if (u1 != null) { context.Users.DeleteObject(u1); context.SaveChanges(); result = true; } } return result; }
public bool ChangeMachineDetails(Credentials c, MachineContents newM, MachineContents oldM) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { oldM.Id = MachineNameToId(context, oldM.Name); Machine m1 = (from o in context.Machines where o.machine_id == oldM.Id select o).SingleOrDefault(); if (m1 == null) return false; m1.machine_name = newM.Name; m1.machine_description = newM.Description; context.SaveChanges(); return true; } }