Esempio n. 1
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;
     }
 }
Esempio n. 2
0
 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;
     }
 }
Esempio n. 3
0
 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;
     }
 }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
 public List<Prop> GetProjectProps(int projectId)
 {
     try
     {
         VestnDB db = new VestnDB();
         List<Prop> projectProps = db.prop.Where(p => p.projectId == projectId).ToList();
         return projectProps;
     }
     catch (Exception ex)
     {
         logAccessor.CreateLog(DateTime.Now, "PropAccessor - GetProjectProps", ex.StackTrace);
         return null;
     }
 }
 public int authenticate(string token)
 {
     VestnDB db = new VestnDB();
     Authentication auth = (from c in db.authentication where c.token == token select c).FirstOrDefault();
     if (auth == null)
     {
         return -1;
     }
     else
     {
         DateTime currentTime = DateTime.Now;
         // want to add time of most recent use of auth token
         return auth.userId;
     }
 }
Esempio n. 8
0
        public Activity GetActivity(int activityId)
        {
            try
            {
                VestnDB db = new VestnDB();
                Activity activity = db.activity.Where(p => p.id == activityId).FirstOrDefault();
                return activity;

            }
            catch (Exception ex)
            {
                logAccessor.CreateLog(DateTime.Now, "ActivityAccessor - GetActivity", ex.StackTrace);
                return null;
            }
        }
Esempio n. 9
0
 //set parentId to 0 when it is at the top level
 public fTag CreateFTag(int parentId, string value)
 {
     fTag tag = new fTag();
     tag.value = value;
     tag.owner = parentId;
     try
     {
         VestnDB db = new VestnDB();
         db.fTag.Add(tag);
         db.SaveChanges();
     }
     catch (InvalidOperationException)
     {
         return null;//bad id
     }
     return (tag);
 }
Esempio n. 10
0
        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;
        }
Esempio n. 11
0
        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
            }
        }
Esempio n. 12
0
        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)
            {
            }
        }
Esempio n. 13
0
        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;
        }
Esempio n. 14
0
        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;
        }
Esempio n. 15
0
 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;
     }
 }
Esempio n. 16
0
        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;
            }
        }
Esempio n. 17
0
 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;
     }
 }
Esempio n. 18
0
 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;
     }
 }
Esempio n. 19
0
        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;
            }
        }
Esempio n. 20
0
        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();
        }
Esempio n. 21
0
        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;
        }
Esempio n. 22
0
 public List<Activity> GetUserActivity(int userId)
 {
     try
     {
         VestnDB db = new VestnDB();
         List<Activity> userActivity = db.activity.Where(p => p.userId == userId).ToList();
         return userActivity;
     }
     catch (Exception ex)
     {
         logAccessor.CreateLog(DateTime.Now, "ActivityAccessor - GetUserActivity", ex.StackTrace);
         return null;
     }
 }
Esempio n. 23
0
 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;
     }
 }
Esempio n. 24
0
        //private void updatePictureElementsForImageGallery()
        //{
        //    UploadManager uploadManager = new UploadManager();
        //    ProjectManager projectManager = new ProjectManager();
        //    List<ProjectElement> projectElements = new VestnDB().projectElements.ToList();
        //    List<ProjectElement_Picture> pictureElements = new List<ProjectElement_Picture>();
        //    foreach (ProjectElement element in projectElements)
        //    {
        //        if (element.GetType() == typeof(ProjectElement_Picture))
        //        {
        //            pictureElements.Add((ProjectElement_Picture)element);
        //        }
        //    }
        //    foreach (ProjectElement_Picture picture in pictureElements)
        //    {
        //        if (picture.pictureGalleriaThumbnailLocation == null)
        //        {
        //            picture.pictureGalleriaThumbnailLocation = uploadManager.generateThumbnail(picture.pictureLocation, picture.id, "PictureElement_Galleria", 1000, 700);
        //            projectManager.UpdateProjectElement(picture);
        //        }
        //    }
        //}
        private void InitializeConnections()
        {
            UserManager userManager = new UserManager();

            List<User> userList = new VestnDB().users.ToList();
            foreach (User user in userList)
            {
                if (user.connections == null)
                {
                    user.connections = "";
                    userManager.UpdateUser(user);
                }
            }
        }
Esempio n. 25
0
 private void InitializeTags()
 {
     VestnDB db = new VestnDB();
     List<sTag> sTags = db.sTag.ToList();
     if (sTags.Count == 0)
     {
         FillFreeLancerTags();
     }
 }
Esempio n. 26
0
 public List<Tag> GetUserTags(int userId)
 {
     VestnDB db = new VestnDB();
     List<UserTags> utList = db.userTags.Where(u => u.userId == userId).ToList();
     List<Tag> tags = new List<Tag>();
     foreach(UserTags entry in utList)
     {
         if (entry.tagType == "s")
         {
             tags.Add(GetSTag(entry.tagId));
         }
         else if (entry.tagType == "f")
         {
             tags.Add(GetFTag(entry.tagId));
         }
     }
     return tags;
 }
Esempio n. 27
0
        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;
        }
Esempio n. 28
0
 private sTag GetEntitySTag(string value)
 {
     VestnDB db = new VestnDB();
     sTag tag = new sTag();
     try
     {
         tag = db.sTag.Where(u => u.value == value).First();
     }
     catch (Exception e)
     {
         return null;
     }
     return tag;
 }
Esempio n. 29
0
 private sTag GetEntitySTag(int id)
 {
     VestnDB db = new VestnDB();
     sTag tag;
     try
     {
         tag = db.sTag.Find(id);
     }
     catch (InvalidOperationException e)
     {
         logAccessor.CreateLog(DateTime.Now, this.GetType().ToString() + "." + System.Reflection.MethodBase.GetCurrentMethod().Name.ToString(), e.ToString());
         return null;
     }
     return tag;
 }
Esempio n. 30
0
 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;
 }