public int AddProjectLink(int tagId, int projectId, string tagType) { ProjectTags pt = new ProjectTags(); pt.tagId = tagId; pt.projectId = projectId; pt.tagType = tagType; VestnDB db = new VestnDB(); ProjectTags fromDatabase = db.projectTags.Where(x => x.tagId == tagId).Where(y => y.projectId == projectId).FirstOrDefault(); if (fromDatabase == null) { try { db.projectTags.Add(pt); db.SaveChanges(); } catch (InvalidOperationException) { return -1;//bad id } return pt.id; } else { return 0; } }
public bool DeleteProp(Prop prop) { try { bool wasDeleted = false; if (prop != null) { VestnDB db = new VestnDB(); db.prop.Attach(prop); db.prop.Remove(prop); db.SaveChanges(); wasDeleted = true; return wasDeleted; } else { return wasDeleted; } } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, "userAccessor - deleteExperience", e.StackTrace); return false; } }
public bool DeleteActivity(Activity activity) { try { bool wasDeleted = false; if (activity != null) { VestnDB db = new VestnDB(); db.activity.Attach(activity); db.activity.Remove(activity); db.SaveChanges(); wasDeleted = true; return wasDeleted; } else { return wasDeleted; } } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, "ActivityAccessor - deleteActivity", e.StackTrace); return false; } }
public int AddUserLink(int tagId, int userId, string tagType) { UserTags ut = new UserTags(); ut.tagId = tagId; ut.userId = userId; ut.tagType = tagType; VestnDB db = new VestnDB(); UserTags fromDatabase = db.userTags.Where(x => x.tagId == tagId).Where(y => y.userId == userId).FirstOrDefault(); if (fromDatabase == null) { try { db.userTags.Add(ut); db.SaveChanges(); } catch (InvalidOperationException) { return -1;//bad id } return ut.id; } else { return 0; } }
public int AddProjectElement(Project project, ProjectElement pe) { if (project == null || pe == null) { return -1; } try { project.projectElements.Add(pe); project.dateModified = DateTime.Now; VestnDB db = new VestnDB(); db.projectElements.Add(pe); db.Entry(project).State = EntityState.Modified; db.SaveChanges(); } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString()); return -1; } try { if (project.projectElementOrder == null) { if (project.projectElements.Count > 1) { project = resetProjectElementOrder(project); //project.projectElementOrder += "," + pe.id; } else { project.projectElementOrder += pe.id; } } else { //project.projectElementOrder += "," + pe.id; project.projectElementOrder = pe.id + "," + project.projectElementOrder; // add new element to the begininning of the order } VestnDB db = new VestnDB(); db.Entry(project).State = EntityState.Modified; db.SaveChanges(); } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString()); return -1; } return pe.id; }
public string logIn(int userId, string userName) { byte[] key = Encoding.ASCII.GetBytes("BrianIsABoss"); DateTime time = DateTime.Now; string dateTime = time.ToString(); string input = dateTime + userId.ToString() + userName; string token = Encode(input, key); Authentication auth = new Authentication(); auth.timeStamp = time; auth.token = token; auth.userId = userId; VestnDB db = new VestnDB(); db.authentication.Add(auth); db.SaveChanges(); return token; }
public void CreateMembershipUser(User user, string password) { //Membership logic MembershipCreateStatus createStatus; Membership.CreateUser(user.userName, password, user.email, null, null, false, null, out createStatus); if (createStatus != MembershipCreateStatus.Success) { } //Entity logic try { VestnDB db = new VestnDB(); //if (user.willingToRelocate == null) //{ // user.willingToRelocate = WillingToRelocateType.undecided; //} if (user.projects == null) { user.projects = new List<Project>(); } if (user.birthDate.Year < 1800) { user.birthDate = new DateTime(1800, 1, 1); } if (user.graduationDate.Year < 1800) { user.graduationDate = new DateTime(1800, 1, 1); } db.users.Add(user); db.SaveChanges(); //fill with projects fillProjects(user); } catch (InvalidOperationException) { //If the entity logic failed, delete the stray MemershipUser Membership.DeleteUser(user.userName); //cant log errors here because of circular dependence } }
public Feedback CreateFeedback(string name, string message, string subject) { Feedback f = new Feedback(); f.name = name; f.message = message; f.subject = subject; try { VestnDB db = new VestnDB(); db.feedback.Add(f); db.SaveChanges(); } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString()); return null;//what to do here? } return f; }
public UserAgreement CreateAgreement(DateTime agreementTime, string userName, string value, string IPAddress) { UserAgreement userAgreement = new UserAgreement(); userAgreement.agreementTime = agreementTime; userAgreement.userName = userName; userAgreement.value = value; userAgreement.IPAddress = IPAddress; try { VestnDB db = new VestnDB(); db.userAgreements.Add(userAgreement); db.SaveChanges(); } catch (Exception e) { LogAccessor logAccessor = new LogAccessor(); logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString()); } return userAgreement; }
public Experience AddExperience(Experience experience) { try { if (experience != null) { VestnDB db = new VestnDB(); db.experience.Add(experience); db.SaveChanges(); return experience; } else { return null; } } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, "userAccessor - AddExperience", e.StackTrace); return null; } }
public bool AddGroupNetwork(int subNetId, int groupNetId) { try { VestnDB db = new VestnDB(); var s = new Network_SubNetwork { id = subNetId }; var g = new Network_Group { id = groupNetId}; db.networks.Attach(s); db.networks.Attach(g); s.groups.Add(g); db.SaveChanges(); return true; } catch (Exception ex) { return false; } }
public Prop AddProp(Prop prop) { try { if (prop != null) { VestnDB db = new VestnDB(); db.prop.Add(prop); db.SaveChanges(); return prop; } else { return null; } } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, "PropAccessor - AddProp", e.StackTrace); return null; } }
public Activity AddActivity(Activity activity) { try { if (activity != null) { VestnDB db = new VestnDB(); db.activity.Add(activity); db.SaveChanges(); return activity; } else { return null; } } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, "activityAccessor - AddActivity", e.StackTrace); return null; } }
public bool AddNetworkUser(int networkId, int userId) { try { VestnDB db = new VestnDB(); var n = new Network { id = networkId }; var u = new User { id = userId }; db.networks.Attach(n); db.users.Attach(u); n.networkUsers.Add(u); db.SaveChanges(); return true; } catch (Exception ex) { LogAccessor la = new LogAccessor(); la.CreateLog(DateTime.Now, "Network Accessor AddAdmin", ex.StackTrace); return false; } }
public void dropData() { VestnDB vestnDB = new VestnDB(); var users = from o in vestnDB.users select o; foreach (User u in users) { vestnDB.users.Remove(u); } var projectElements = from o in vestnDB.projectElements select o; foreach (ProjectElement p in projectElements) { vestnDB.projectElements.Remove(p); } var projects = from o in vestnDB.projects select o; foreach (Project p in projects) { vestnDB.projects.Remove(p); } vestnDB.SaveChanges(); }
public Activity UpdateActivity(Activity activity) { try { if (activity != null) { VestnDB db = new VestnDB(); db.Entry(activity).State = EntityState.Modified; db.SaveChanges(); return activity; } else { return null; } } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, "ActivityAccessor - UpdateActivity", e.StackTrace); return null; } }
//set parentId to 0 when it is at the top level public sTag CreateSTag(int parentId, string value) { sTag tag = new sTag(); tag.value = value; tag.parentId = parentId; try { VestnDB db = new VestnDB(); db.sTag.Add(tag); db.SaveChanges(); } catch (InvalidOperationException) { return null;//bad id } return (tag); }
public bool SetVerifyHash(int userId, string hash) { try { VestnDB db = new VestnDB(); User u = new User { id = userId }; db.users.Attach(u); u.verifyEmailHash = hash; db.SaveChanges(); return true; } catch (Exception) { return false; } }
public sTag UpdateSTag(sTag tag) { sTag oldTag = GetSTag(tag.id); if (oldTag.value != tag.value) { return tag; } try { VestnDB db = new VestnDB(); db.Entry(tag).State = EntityState.Modified; db.SaveChanges(); } catch (InvalidOperationException) { return null; } return tag; }
public bool removeUserLink(int tagId, int userId) { VestnDB db = new VestnDB(); UserTags ut = db.userTags.Where(u => u.userId == userId).Where(t => t.tagId == tagId).FirstOrDefault(); try { db.userTags.Attach(ut); ut = db.userTags.Remove(ut); db.SaveChanges(); } catch (Exception) { return false; } return true; }
public bool VerifyEmail(int userId) { try { VestnDB db = new VestnDB(); User u = new User { id = userId }; db.users.Attach(u); u.emailVerified = 1; db.SaveChanges(); return true; } catch (Exception ex) { return false; } }
public Reference UpdateReference(Reference reference) { try { if (reference != null) { VestnDB db = new VestnDB(); db.Entry(reference).State = EntityState.Modified; db.SaveChanges(); return reference; } else { return null; } } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, "userAccessor - UpdateReference", e.StackTrace); return null; } }
public sTag DeleteSTag(sTag tag) { VestnDB db = new VestnDB(); db.sTag.Attach(tag); tag = db.sTag.Remove(tag); db.SaveChanges(); return tag; }
public User UpdateUser(User user) { if (user == null) { return null; } User u = new User { id = user.id }; if (user.profileURL == null) { u.profileURL = user.userName; } User oldUser = GetUser(user.id); //throw error if we attempt to change username //we will probably implement this later but we are still //wrestling conceptually with it if (oldUser.userName != user.userName) { return null; } //Membership logic if we updated the email address //(or username in the future) if (oldUser.email != user.email) { MembershipUser membershipUser = Membership.GetUser(oldUser.userName); membershipUser.Email = user.email; Membership.UpdateUser(membershipUser); } if (user.graduationDate.Year < 1800) { u.graduationDate = new DateTime(1800, 1, 1); } if (user.birthDate.Year < 1800) { u.birthDate = new DateTime(1800, 1, 1); } //Entity logic for everything else (except password) try { VestnDB db = new VestnDB(); //db.users.Attach(u); var updatedUser = db.users.Find(user.id); db.users.Attach(updatedUser); //db.Entry(user).State = EntityState.Modified; updatedUser.description = user.description; updatedUser.email = user.email; updatedUser.facebookLink = user.facebookLink; updatedUser.linkedinLink = user.linkedinLink; updatedUser.twitterLink = user.twitterLink; updatedUser.firstName = user.firstName; updatedUser.lastName = user.lastName; updatedUser.major = user.major; updatedUser.location = user.location; updatedUser.phoneNumber = user.phoneNumber; updatedUser.projectOrder = user.projectOrder; updatedUser.organization = user.organization; updatedUser.tagLine = user.tagLine; updatedUser.title = user.title; updatedUser.isPublic = user.isPublic; updatedUser.resume = user.resume; updatedUser.profilePicture = user.profilePicture; updatedUser.profilePictureThumbnail = user.profilePictureThumbnail; updatedUser.networkPictureThumbnail = user.networkPictureThumbnail; updatedUser.profileURL = user.profileURL; updatedUser.forgotPasswordHash = user.forgotPasswordHash; updatedUser.verifyEmailHash = user.verifyEmailHash; updatedUser.profileViews = user.profileViews; db.SaveChanges(); } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString()); return null; } return user; }
public void AddProjectIdToOrder(int newProjectId, User user) { try { VestnDB db = new VestnDB(); User u = new User { id = user.id }; db.users.Attach(u); u.projectOrder = user.projectOrder; if (u.projectOrder == null) { List<int> currentProjects = new List<int>(); string newProjectOrder = null; foreach (Project p in user.projects) { if (p.isActive == true && p.privacy != "deleted") { currentProjects.Add(p.id); } } foreach (int y in currentProjects) { newProjectOrder += y + " "; } newProjectOrder = newProjectOrder.TrimEnd().Replace(' ', ','); u.projectOrder = newProjectOrder; user.projectOrder = newProjectOrder; } else { u.projectOrder = newProjectId.ToString() + "," + u.projectOrder; user.projectOrder = newProjectId.ToString() + "," + user.projectOrder; //u.projectOrder += ("," + newProjectId.ToString()); //user.projectOrder += ("," + newProjectId.ToString()); } db.SaveChanges(); } catch (Exception ex) { } }
private void fillProjects(User u) { VestnDB vestnDB = new VestnDB(); Project project = new Project { name = "Test Project", description = "Test Description", }; //Project Elements ProjectElement_Information informationElement; ProjectElement_Experience experienceElement; ProjectElement_Document documentElement; ProjectElement_Video videoElement; ProjectElement_Picture pictureElement; List<ProjectElement> projectElements; informationElement = new ProjectElement_Information { location = "Here", email = "*****@*****.**", school= "Univeristy of Nebraska- Lincoln", phone = "402-402-4111", major = "Actuarial Science", minor = "Business Administration", description = "tetetetetet" }; documentElement = new ProjectElement_Document { description = "im a document", documentLocation = "asdfasdf" }; experienceElement = new ProjectElement_Experience { jobTitle = "Owner", description = "I'm CEO Bitch.", startDate = new DateTime(1991, 6, 12), endDate = new DateTime(2011, 6, 12) }; pictureElement = new ProjectElement_Picture { description = "im a picture", pictureLocation = "sadfsadfsa" }; videoElement = new ProjectElement_Video { //put a test id you know in here haun videoId = "xxxxx", description = "asdfsadfasdf" }; projectElements = new List<ProjectElement>(); projectElements.Add(informationElement); projectElements.Add(experienceElement); projectElements.Add(documentElement); projectElements.Add(pictureElement); projectElements.Add(videoElement); //Save elements to project project.projectElements = projectElements; //Save Changes to DB VestnDB db = new VestnDB(); db.projects.Add(project); if (u.projects == null) { u.projects = new List<Project>(); } u.projects.Add(project); db.Entry(u).State = EntityState.Modified; db.SaveChanges(); }
public bool updateUserSettings(User user) { try { VestnDB db = new VestnDB(); var u = db.users.Find(user.id); db.users.Attach(u); u.isPublic = user.isPublic; u.email = user.email; u.profileURL = user.profileURL; db.SaveChanges(); return true; } catch(Exception ex) { return false; } }
private void fillUsers() { VestnDB vestnDB = new VestnDB(); User user = new User { userName = "******", email = "*****@*****.**", firstName = "database", lastName = "test", birthDate = DateTime.Now, graduationDate = DateTime.Now.AddYears(1), tagIds = null, location = "Lincoln, Ne", organization = "Univeristy of Nebraska-Lincoln", major= "Testing", phoneNumber = "555-555-5555", //willingToRelocate = WillingToRelocateType.no, }; User user2 = new User { userName = "******", email = "*****@*****.**", firstName = "database2", lastName = "test2", birthDate = DateTime.Now, graduationDate = DateTime.Now.AddYears(1), tagIds = null, location = "Omaha, Ne", organization = "Univeristy of Nebraska-Omaha", major = "Testing2", phoneNumber = "222-222-2222", //willingToRelocate = WillingToRelocateType.yes, }; vestnDB.users.Add(user); vestnDB.users.Add(user2); vestnDB.SaveChanges(); fillProjects(user); fillProjects(user2); }
public bool removeProjectLink(int tagId, int projectId, string type) { VestnDB db = new VestnDB(); ProjectTags pt = db.projectTags.Where(p => p.projectId == projectId).Where(t => t.tagId == tagId).Where(q => q.tagType == type).FirstOrDefault(); try { db.projectTags.Attach(pt); pt = db.projectTags.Remove(pt); db.SaveChanges(); } catch (Exception) { return false; } return true; }
private User UpdateEntityUser(User user) { //Entity logic for username update try { VestnDB db = new VestnDB(); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } catch (Exception e) { logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString()); return null; } return user; }