public string removeWorkerFromCompany(Guid id, CompaniesR c) { var check = false; List <Guid> temp = new List <Guid>(); if (c.Employees != null) { for (int i = 0; i < c.Employees.Count; i++) { if (id != c.Employees[i]) { temp.Add(c.Employees[i]); } else { check = true; } } c.Employees = temp; _session.Store(c); _session.SaveChanges(); if (check == true) { return("Worker removed from company!"); } else { return("Such worker never existed in registry!"); } } else { return("Such worker doesn't exist in registry!"); } }
public string enterNewCompanyInRDb(string company, string owner, string type, string location, string mail, string pass) { CompaniesR c = new CompaniesR() { CompanyName = company, Owner = owner, Type = type, Location = location, Email = mail, Password = pass }; var ret = raven.CreateCompany(c); //mongo Companies cm = new Companies() { CompanyName = company, Owner = owner, Type = type, Location = location, Email = mail, Password = pass }; var retm = mongor.CreateCompany(cm); DBCheck dbc = new DBCheck() { Collection = "company", DbName = "raven", Mail = mail, Password = pass, MongoId = retm.Id.ToString(), RavenId = c.Id.ToString() }; var dbcRet = raven.setDB(dbc); Changes ch = new Changes() { Actor1 = ret.Id, Actor1Name = ret.CompanyName, Actor1Collection = "CompaniesR", Type = " is new company that has joined our network!", Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; var change = raven.addFriendChange(ch); if (ret != null && change != null && retm != null && dbcRet != null) { HttpContext.Current.Session.Add("companyR", ret); HttpContext.Current.Session.Add("database", dbc.DbName); return(succ); } return(fail); }
public string deleteCompanyWithId(string id) { Companies cm = mongoDbase.getCompanyById(ObjectId.Parse(id)); CompaniesR c = raven.getCompanyByEmail(cm.Email); if (c != null && cm != null) { if (c.Employees != null && cm.Employees != null) { for (int i = 0; i < c.Employees.Count; i++) { var temp = raven.getWorkerById(c.Employees[i]); temp.CompanyId = null; temp.CompanyName = null; raven.updateWorker(temp); } //mongo for (int i = 0; i < cm.Employees.Count; i++) { var temp = mongoDbase.getWorkerById(cm.Employees[i]); temp.CompanyId = null; temp.CompanyName = null; mongoDbase.updateWorker(temp); } } } var res = raven.deleteCompany(c); var resm = mongoDbase.removeCompany(cm.Id); var resdb = raven.deleteDBprefEntry(c.Id.ToString(), c.Email, c.Password); Changes ch = new Changes() { Actor1 = c.Id, Actor1Name = c.CompanyName, Actor1Collection = "CompaniesR", Type = " has deleted profile from the network!", Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; Changes changeFinal = raven.addFriendChange(ch); if (res != null && resm != null && changeFinal != null) { return("Company deleted!"); } else { return("Company not found!"); } }
public string retCompanyFromIdR(string id) { CompaniesR c = raven.getCompanyById(Guid.Parse(id)); if (c != null) { return(JsonConvert.SerializeObject(c)); } else { return("Company not found!"); } }
public string addWorkerToCompany(Guid id, CompaniesR c) { if (c.Employees == null) { c.Employees = new List <Guid>(); c.Employees.Add(id); } else { c.Employees.Add(id); } _session.Store(c); _session.SaveChanges(); return("Worker added to the company!"); }
public string returnCompanyFromEmailR(string mail, string pass) { CompaniesR w = raven.getCompanyByEmail(mail); if (w != null) { if (w.Password == pass && w.Email == mail) { HttpContext.Current.Session.Add("companyR", w); HttpContext.Current.Session.Add("database", "raven"); HttpContext.Current.Session.Add("userR", null); return(JsonConvert.SerializeObject(w)); } return(badp); } else { return(badm); } }
public string deleteWorkerWithId(string id) { Workers wm = mongoDbase.getWorkerById(ObjectId.Parse(id)); WorkersR w = raven.getWorkerByEmail(wm.Email); if (w != null && wm != null) { if (w.Friends != null && wm.Friends != null) { for (int i = 0; i < w.Friends.Count; i++) { var temp = raven.getWorkerById(w.Friends[i]); List <Guid> tpr = new List <Guid>(); for (int j = 0; j < temp.Friends.Count; j++) { if (Guid.Parse(id) != temp.Friends[j]) { tpr.Add(temp.Friends[j]); } } temp.Friends = tpr; raven.updateWorker(temp); } //mongo for (int i = 0; i < wm.Friends.Count; i++) { var temp = mongoDbase.getWorkerById(wm.Friends[i]); List <ObjectId> tpr = new List <ObjectId>(); for (int j = 0; j < temp.Friends.Count; j++) { if (ObjectId.Parse(id) != temp.Friends[j]) { tpr.Add(temp.Friends[j]); } } temp.Friends = tpr; mongoDbase.updateWorker(temp); } } if (w.CompanyName != null && wm.CompanyName != null) { CompaniesR c = raven.getCompanyById(Guid.Parse(w.CompanyId)); List <Guid> tpr = new List <Guid>(); for (int j = 0; j < c.Employees.Count; j++) { if (Guid.Parse(id) != c.Employees[j]) { tpr.Add(c.Employees[j]); } } c.Employees = tpr; raven.updateCompany(c); //mongo Companies cm = mongoDbase.getCompanyById(ObjectId.Parse(wm.CompanyId)); List <ObjectId> tpm = new List <ObjectId>(); for (int j = 0; j < cm.Employees.Count; j++) { if (ObjectId.Parse(id) != cm.Employees[j]) { tpm.Add(cm.Employees[j]); } } cm.Employees = tpm; mongoDbase.updateCompany(cm); } } var res = raven.deleteWorker(w); var resm = mongoDbase.removeWorker(wm.Id); var resdb = raven.deleteDBprefEntry(w.Id.ToString(), w.Email, w.Password); Changes ch = new Changes() { Actor1 = w.Id, Actor1Name = w.FirstName + ' ' + w.LastName, Actor1Collection = "WorkersR", Type = " has deleted profile from the network!", Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; Changes changeFinal = raven.addFriendChange(ch); if (res != null && resm != null && changeFinal != null) { return("Worker deleted!"); } else { return("Worker not found!"); } }
public string updateCompanyInDb(string id, string mail, string pass, string name, string owner, string type, string loc, string dbch) { Companies recvm = mongoDbase.getCompanyById(ObjectId.Parse(id)); CompaniesR recvv = raven.getCompanyByEmail(recvm.Email); recvv.Email = recvm.Email = mail; recvv.Password = recvm.Password = pass; recvv.Owner = recvm.Owner = owner; recvv.Location = recvm.Location = loc; var temp = recvv.CompanyName; var cId = raven.getCompanyByName(name); Changes changeFinal = null; if (cId.Count == 0) { return("There is no such company!"); } if (temp != name && temp != null) { var tempC = raven.getCompanyByName(temp); for (int i = 0; i < tempC[0].Employees.Count; i++) { var tempE = raven.getWorkerById(tempC[0].Employees[i]); tempE.CompanyName = name; raven.updateWorker(tempE); } recvv.CompanyName = name; } else if (temp == null) { recvv.CompanyName = name; } var res = raven.updateCompany(recvv); //mongo if (temp != name && temp != null) { var tempC = mongoDbase.getCompanyByName(temp); for (int i = 0; i < tempC[0].Employees.Count; i++) { var tempE = mongoDbase.getWorkerById(tempC[0].Employees[i]); tempE.CompanyName = name; mongoDbase.updateWorker(tempE); } recvm.CompanyName = name; } else if (temp == null) { recvm.CompanyName = name; } var resm = mongoDbase.updateCompany(recvm); Changes ch = new Changes() { Actor1 = res.Id, Actor1Name = res.CompanyName, Actor1Collection = "CompaniesR", Type = " has updated profile!", Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; changeFinal = raven.addFriendChange(ch); var dbTemplist = raven.getDBPref(); string dbtemp = null; if (dbTemplist.Count != 0) { for (int i = 0; i < dbTemplist.Count; i++) { if (dbTemplist[i].MongoId == recvm.Id.ToString() && dbTemplist[i].RavenId == recvv.Id.ToString()) { dbtemp = dbTemplist[i].DbName; } } if (dbtemp == null) { DBCheck dbc = new DBCheck() { Collection = "company", DbName = "raven", Mail = mail, Password = pass, MongoId = recvm.Id.ToString(), RavenId = recvv.Id.ToString() }; var dbcRet = raven.setDB(dbc); } } if (dbtemp != null && dbtemp != dbch) { DBCheck dbc = new DBCheck() { Collection = "company", DbName = dbch, Mail = mail, Password = pass, MongoId = recvm.Id.ToString(), RavenId = recvv.Id.ToString() }; var dbcRet = raven.setDB(dbc); } if (res != null && resm != null && changeFinal != null) { if (dbch == "raven") { HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Add("companyR", res); HttpContext.Current.Session.Add("database", "raven"); return("Update successfull!"); } else if (dbch == "mongo") { HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Add("company", resm); HttpContext.Current.Session.Add("database", "mongo"); return("Update successfull!"); } } return(fail); }
public CompaniesR CreateCompany(CompaniesR c) { _session.Store(c); _session.SaveChanges(); return(c); }
public string deleteCompany(CompaniesR c) { _session.Delete <CompaniesR>(c); _session.SaveChanges(); return("Company deleted!"); }