public FileItResponse AddUpdateUser(string user, string pass, FileItUser userobj) { var response = new FileItResponse(); using (var db = new FileItDataLayer.Models.SystemFileitEntities()) { var loginUser = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase)); if (loginUser.Authenticate(pass)) { var userDb = db.USERS.FirstOrDefault(u => u.USERNAME == userobj.UserName); if (userDb == null) { userDb = new FileItDataLayer.Models.USER(); } if (userDb != null) { if (userobj.MergeWithDB(userDb)) { db.SaveChanges(); response.Success = true; } } } } return(response); }
public FileItResponse SetUserPassword(string user, string pass, string targetuser, string newpass) { var response = new FileItResponse(); using (var db = new FileItDataLayer.Models.SystemFileitEntities()) { var userObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(user, StringComparison.CurrentCultureIgnoreCase)); var targetUserObj = db.USERS.FirstOrDefault(u => u.USERNAME.Equals(targetuser, StringComparison.CurrentCultureIgnoreCase)); if (userObj != null && targetUserObj != null && userObj.Authenticate(pass)) { targetUserObj.PASS = newpass; db.SaveChanges(); response.Success = true; } } return(response); }
public static bool Create(string cabinetName, ref string cabinetId, string username, TEMPLATE template, string dataPath, string cabinetTemplatePath) { var result = false; var cabinetNameValidated = cabinetName; //get a valid cabinetId //validate cabinet name cabinetId = GenerateCabinetId(cabinetName, ref cabinetNameValidated); //create all folder paths var paths = new List <string>() { Path.Combine(FileItDataPath, cabinetId), Path.Combine(FileItDataPath, cabinetId, "oStore"), Path.Combine(FileItDataPath, cabinetId, "tStore"), Path.Combine(FileItDataPath, cabinetId, "wStore") }; paths.ToList().ForEach(p => { if (!Directory.Exists(p)) { Directory.CreateDirectory(p); } }); //copy the template to the correct location (rename in the process) var newCabinetFilePath = Path.Combine(FileItDataPath, cabinetId, cabinetId + ".FILEIT"); File.Copy(EmptyCabinetFilePath, newCabinetFilePath); using (var db = new SystemFileitEntities()) { if (!db.TEMPLATES.Any(t => t.TEMPLATENAME.Equals(template.TEMPLATENAME, StringComparison.CurrentCultureIgnoreCase))) { template.DESCRIPTION = "Auto Template From SVC"; template.ACCOUNT = "[Default System Account]"; db.TEMPLATES.Add(template); template.TemplateDefinitions.ToList().ForEach(td => { td.TEMPLATENAME = template.TEMPLATENAME; db.TEMPLATE_DEFINITION.Add(td); }); db.SaveChanges(); } } //add tables to the empty FILEIT db var newCabinet = new CABINET() { CABINETID = cabinetId, CABINETNAME = cabinetNameValidated, CABINETFULLPATH = newCabinetFilePath, ROOTPATH = Path.Combine(FileItDataPath, cabinetId), OSTOREPATH = Path.Combine(FileItDataPath, cabinetId, "oStore"), TSTOREPATH = Path.Combine(FileItDataPath, cabinetId, "tStore"), WSTOREPATH = Path.Combine(FileItDataPath, cabinetId, "wStore"), ACCOUNT = "Default System Account", ADMINISTRATOR = username, DESCRIPTION = "FileIt Service Created Cabinet", TEMPLATENAME = template.TEMPLATENAME }; newCabinet.CreateTables(); //create CABINET record using (var db = new SystemFileitEntities()) { db.CABINETS.Add(newCabinet); newCabinet.SetAccess("user", username, true); db.SaveChanges(); } result = true; return(result); }