public void Activate(Projects project)
        {
            Projects dbEntry = context.Projects.Find(project.Id);

            if (dbEntry != null)
            {
                dbEntry.Active = "Aktywny";
            }
            context.SaveChanges();
        }
        public ActionResult Create([Bind(Include = "ProjectId,ProjectName,ProjectDescription,ProjectScreenshot,ProjectGitHub")] Project project)
        {
            if (ModelState.IsValid)
            {
                db.Projects.Add(project);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(project));
        }
        public int ClearForgottenPasswordsByUser(tblUser user)
        {
            try
            {
                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    var links = (from link in dc.tblForgotPasswords
                                 join u in dc.tblUsers on link.UserId equals u.Id
                                 where link.UserId == user.Id
                                 select new
                    {
                        link.Id,
                        link.UserId,
                        link.ExpirationDate
                    }).ToList();

                    foreach (var link in links)
                    {
                        tblForgotPassword forgottenpass = dc.tblForgotPasswords.Where(p => p.Id == link.Id).FirstOrDefault();
                        forgottenpass.Id             = link.Id;
                        forgottenpass.ExpirationDate = link.ExpirationDate;
                        forgottenpass.UserId         = link.UserId;
                        dc.tblForgotPasswords.Remove(forgottenpass);
                    }
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        public void InsertTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Create a user
                tblUser user = new tblUser
                {
                    //User a GUID for testing purposes
                    Id           = Guid.Parse("11112222-3333-4444-5555-666677778888"),
                    Email        = "*****@*****.**",
                    Password     = "******",
                    FirstName    = "Test",
                    LastName     = "Test",
                    ProfileImage = "Test.Test",
                    UserTypeId   = Guid.NewGuid()
                };

                //Add the user to the database
                dc.tblUsers.Add(user);

                //Commit changes
                int rowsInserted = dc.SaveChanges();

                Assert.IsTrue(rowsInserted == 1);
            }
        }
Exemple #5
0
        public int Update()
        {
            try
            {
                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    tblPortfolio portfolio = dc.tblPortfolios.Where(p => p.Id == Id).FirstOrDefault();
                    if (portfolio != null)
                    {
                        portfolio.Name           = Name;
                        portfolio.Description    = Description;
                        portfolio.PrivacyId      = PrivacyId;
                        portfolio.PortfolioImage = PortfolioImage;
                        portfolio.UserId         = UserId;

                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Portfolio not found");
                    }
                }
            }
            catch (Exception ex) { throw ex; }
        }
Exemple #6
0
        /// <summary>
        /// Insert project into portfolio
        /// </summary>
        /// <param name="projectId"> Id of Project to add to Portfolio object </param>
        /// <returns> bool for success status </returns>
        public bool AddProject(Guid projectId)
        {
            try
            {
                Project project = new Project();
                project.LoadById(projectId);
                Portfolio   port = new Portfolio();
                ProjectList prjs = new ProjectList();
                prjs = port.LoadProjects(port.Id);
                foreach (Project prj in prjs)
                {
                    if (prj.Name == project.Name)
                    {
                        // Already exists in Portfolio
                        return(false); //this should probably be a throw ex
                    }
                }


                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    tblPortfolio        portfolio = dc.tblPortfolios.Where(p => p.Id == Id).FirstOrDefault();
                    tblPortfolioProject portProj  = new tblPortfolioProject()
                    {
                        Id          = Guid.NewGuid(),
                        ProjectId   = projectId,
                        PortfolioId = portfolio.Id
                    };
                    dc.tblPortfolioProjects.Add(portProj);
                    dc.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex) { throw ex; }
        }
Exemple #7
0
        //------------------- END CONSTRUCTORS ---------------------
        #endregion Constructors

        #region User Password
        //------------------- START PASSWORD METHODS ---------------------

        // Update Password
        public int UpdatePassword(string password, string oldpassword, Guid userId)
        {
            try
            {
                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    tblUser user = dc.tblUsers.Where(u => u.Id == Id).FirstOrDefault();
                    if (user != null)
                    {
                        if (user.Password == GetHash(oldpassword, user.Id))
                        {
                            user.Password = GetHash(password, user.Id);
                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("Incorrect Password");
                        }
                    }
                    else
                    {
                        throw new Exception("User not found");
                    }
                }
            }
            catch (Exception ex) { throw ex; }
        }
Exemple #8
0
 // Change Password from Forgot password key
 public int ChangeForgottenPassword(string password)
 {
     try
     {
         using (PortfolioEntities dc = new PortfolioEntities())
         {
             tblForgotPassword forgottenpass = dc.tblForgotPasswords.Where(u => u.UserId == Id).FirstOrDefault();
             if ((DateTime.Now) < (forgottenpass.ExpirationDate))
             {
                 // Current time is earlier than expiration date of reset link
                 tblUser user = dc.tblUsers.Where(u => u.Id == Id).FirstOrDefault();
                 if (user != null)
                 {
                     // User exists
                     user.Password = GetHash(password, user.Id);
                     return(dc.SaveChanges());
                 }
                 else
                 {
                     throw new Exception("User not found");
                 }
             }
             else
             {
                 throw new Exception("Password Reset Link Expired");
             }
         }
     }
     catch (Exception ex) { throw ex; }
 }
Exemple #9
0
        //------------------- START STANDARD INSERT UPDATE DELETE METHODS ---------------------

        // Standard Insert Method
        public int Insert()
        {
            try
            {
                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    Guid    userId = Guid.NewGuid();
                    tblUser user   = new tblUser()
                    {
                        Id           = userId,
                        Email        = Email,
                        Password     = GetHash(this.Password, userId),
                        FirstName    = FirstName,
                        LastName     = LastName,
                        ProfileImage = ProfileImage,
                        UserTypeId   = UserTypeId,
                        Username     = Username,
                        Bio          = Bio
                    };

                    //Save the Id
                    this.Id = user.Id;
                    dc.tblUsers.Add(user);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex) { throw ex; }
        }
Exemple #10
0
 public int Delete()
 {
     try
     {
         using (PortfolioEntities dc = new PortfolioEntities())
         {
             tblProject project = dc.tblProjects.Where(p => p.Id == Id).FirstOrDefault();
             if (project != null)
             {
                 ProjectLanguageList pll = new ProjectLanguageList();
                 pll.LoadByProjectId(project.Id);
                 foreach (ProjectLanguage pl in pll)
                 {
                     pl.Delete();
                 }
                 dc.tblProjects.Remove(project);
                 return(dc.SaveChanges());
             }
             else
             {
                 throw new Exception("Project not found");
             }
         }
     }
     catch (Exception ex) { throw ex; }
 }
Exemple #11
0
 // Standard Update Method
 public int Update()
 {
     try
     {
         using (PortfolioEntities dc = new PortfolioEntities())
         {
             // Password is done in seperate Passwordupdate Method
             tblUser user = dc.tblUsers.Where(u => u.Id == Id).FirstOrDefault();
             if (user != null)
             {
                 user.Email        = Email;
                 user.FirstName    = FirstName;
                 user.LastName     = LastName;
                 user.ProfileImage = ProfileImage;
                 user.UserTypeId   = UserTypeId;
                 user.Username     = Username;
                 user.Bio          = Bio;
                 return(dc.SaveChanges());
             }
             else
             {
                 throw new Exception("User not found");
             }
         }
     }
     catch (Exception ex) { throw ex; }
 }
Exemple #12
0
 // Inserts project without portfolio
 public void Insert(Guid userId)
 {
     try
     {
         using (PortfolioEntities dc = new PortfolioEntities())
         {
             tblProject project = new tblProject()
             {
                 Id            = Guid.NewGuid(),
                 Name          = Name,
                 Location      = Location,
                 Filepath      = Filepath,
                 PrivacyId     = PrivacyId,
                 Image         = Image,
                 Description   = Description,
                 UserId        = userId,
                 DateCreated   = DateCreated,
                 Purpose       = Purpose,
                 Environment   = Environment,
                 Challenges    = Challenges,
                 FuturePlans   = FuturePlans,
                 Collaborators = Collaborators,
                 LastUpdated   = LastUpdated,
                 SoftwareUsed  = SoftwareUsed,
                 StatusId      = StatusId
             };
             dc.tblProjects.Add(project);
             dc.SaveChanges();
         }
     }
     catch (Exception ex) { throw ex; }
 }
        public ActionResult Create(Portfolio portfolio, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                string path = Path.Combine(Server.MapPath("../Images"),
                                           Path.GetFileName(file.FileName));
                file.SaveAs(path);
                portfolio.ImagePath = Path.Combine(("../Images/"), Path.GetFileName(file.FileName));
                ViewBag.Message     = "File uploaded successfully";
            }

            if (ModelState.IsValid)
            {
                db.Portfolios.Add(portfolio);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(portfolio));
        }
Exemple #14
0
        public void DeleteTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                Guid          screenshotGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");
                tblScreenshot screenshot     = dc.tblScreenshots.FirstOrDefault(s => s.Id == screenshotGuid);

                dc.tblScreenshots.Remove(screenshot);

                dc.SaveChanges();

                tblScreenshot deletedScreenshot = dc.tblScreenshots.FirstOrDefault(s => s.Id == screenshotGuid);

                Assert.IsNull(deletedScreenshot);
            }
        }
Exemple #15
0
        public void DeleteTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                Guid       privacyGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");
                tblPrivacy privacy     = dc.tblPrivacies.FirstOrDefault(u => u.Id == privacyGuid);

                dc.tblPrivacies.Remove(privacy);

                dc.SaveChanges();

                tblPrivacy deletedPrivacy = dc.tblPrivacies.FirstOrDefault(u => u.Id == privacyGuid);

                Assert.IsNull(deletedPrivacy);
            }
        }
Exemple #16
0
        public void DeleteTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                Guid      statusGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");
                tblStatus status     = dc.tblStatuses.FirstOrDefault(s => s.Id == statusGuid);

                dc.tblStatuses.Remove(status);

                dc.SaveChanges();

                tblStatus deletedStatus = dc.tblStatuses.FirstOrDefault(s => s.Id == statusGuid);

                Assert.IsNull(deletedStatus);
            }
        }
Exemple #17
0
        public void DeleteTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                Guid       projectGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");
                tblProject project     = dc.tblProjects.FirstOrDefault(p => p.Id == projectGuid);

                dc.tblProjects.Remove(project);

                dc.SaveChanges();

                tblProject deletedProject = dc.tblProjects.FirstOrDefault(p => p.Id == projectGuid);

                Assert.IsNull(deletedProject);
            }
        }
Exemple #18
0
        public void DeleteTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                Guid        languageGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");
                tblLanguage language     = dc.tblLanguages.FirstOrDefault(l => l.Id == languageGuid);

                dc.tblLanguages.Remove(language);

                dc.SaveChanges();

                tblLanguage deletedLanguage = dc.tblLanguages.FirstOrDefault(l => l.Id == languageGuid);

                Assert.IsNull(deletedLanguage);
            }
        }
Exemple #19
0
        public void DeleteTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                Guid    userGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");
                tblUser user     = dc.tblUsers.FirstOrDefault(u => u.Id == userGuid);

                dc.tblUsers.Remove(user);

                dc.SaveChanges();

                tblUser deletedUser = dc.tblUsers.FirstOrDefault(u => u.Id == userGuid);

                Assert.IsNull(deletedUser);
            }
        }
Exemple #20
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test status based on ID and update it
                Guid statusGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblStatus status = dc.tblStatuses.FirstOrDefault(s => s.Id == statusGuid);

                status.Description = "UpdatedDescription";

                //Save changes and get it back out
                dc.SaveChanges();
                tblStatus updatedStatus = dc.tblStatuses.FirstOrDefault(s => s.Description == "UpdatedDescription");
                //Make sure the Ids match
                Assert.AreEqual(status.Id, updatedStatus.Id);
            }
        }
Exemple #21
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test privacy based on ID and update it
                Guid privacyGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblPrivacy privacy = dc.tblPrivacies.FirstOrDefault(u => u.Id == privacyGuid);

                privacy.Description = "UpdatedPrivacy";

                //Save changes and get it back out
                dc.SaveChanges();
                tblPrivacy updatedPrivacy = dc.tblPrivacies.FirstOrDefault(u => u.Description == "UpdatedPrivacy");
                //Make sure the Ids match
                Assert.AreEqual(privacy.Id, updatedPrivacy.Id);
            }
        }
Exemple #22
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test language based on ID and update it
                Guid languageGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblLanguage language = dc.tblLanguages.FirstOrDefault(l => l.Id == languageGuid);

                language.Description = "UpdatedLang";

                //Save changes and get it back out
                dc.SaveChanges();
                tblLanguage updatedLanguage = dc.tblLanguages.FirstOrDefault(l => l.Description == "UpdatedLang");
                //Make sure the Ids match
                Assert.AreEqual(language.Id, updatedLanguage.Id);
            }
        }
Exemple #23
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test userType based on ID and update it
                Guid userTypeGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblUserType userType = dc.tblUserTypes.FirstOrDefault(u => u.Id == userTypeGuid);

                userType.Description = "UpdatedUserType";

                //Save changes and get it back out
                dc.SaveChanges();
                tblUserType updatedUserType = dc.tblUserTypes.FirstOrDefault(u => u.Description == "UpdatedUserType");
                //Make sure the Ids match
                Assert.AreEqual(userType.Id, updatedUserType.Id);
            }
        }
Exemple #24
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test user based on ID and update it
                Guid projectGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblProject project = dc.tblProjects.FirstOrDefault(p => p.Id == projectGuid);

                Guid privacyGuid = Guid.Parse("88887777-6666-5555-4444-333322221111");
                project.PrivacyId = privacyGuid;

                //Save changes and get it back out
                dc.SaveChanges();
                tblProject updatedProject = dc.tblProjects.FirstOrDefault(p => p.PrivacyId == privacyGuid);
                //Make sure the Ids match
                Assert.AreEqual(project.Id, updatedProject.Id);
            }
        }
Exemple #25
0
 // Adds project to porfolio
 public void AddToPortfolio(Guid portfolioId)
 {
     try
     {
         using (PortfolioEntities dc = new PortfolioEntities())
         {
             tblProject          project  = dc.tblProjects.Where(p => p.Id == Id).FirstOrDefault();
             tblPortfolioProject portProj = new tblPortfolioProject()
             {
                 Id          = Guid.NewGuid(),
                 PortfolioId = portfolioId,
                 ProjectId   = project.Id
             };
             dc.tblPortfolioProjects.Add(portProj);
             dc.SaveChanges();
         }
     }
     catch (Exception ex) { throw ex; }
 }
        public Profile SaveProfile(Profile profile)
        {
            Profile dbEntry = context.Profile.FirstOrDefault();

            if (dbEntry != null)
            {
                dbEntry.Description = profile.Description;
                dbEntry.Image       = profile.Image;
                dbEntry.Name        = profile.Name;
                dbEntry.Surname     = profile.Surname;
            }
            else
            {
                context.Profile.Add(profile);
            }

            context.SaveChanges();
            return(dbEntry);
        }
        public int Insert()
        {
            try
            {
                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    tblProjectLanguage projectlanguage = new tblProjectLanguage();

                    projectlanguage.Id         = Guid.NewGuid();
                    projectlanguage.ProjectId  = this.ProjectId;
                    projectlanguage.LanguageId = this.LanguageId;
                    this.Id = projectlanguage.Id;

                    dc.tblProjectLanguages.Add(projectlanguage);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex) { throw ex; }
        }
Exemple #28
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test user based on ID and update it
                Guid userGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblUser user = dc.tblUsers.FirstOrDefault(u => u.Id == userGuid);

                Guid userTypeGuid = Guid.Parse("88887777-6666-5555-4444-333322221111");
                user.UserTypeId = userTypeGuid;

                //Save changes and get it back out
                dc.SaveChanges();
                tblUser updatedUser = dc.tblUsers.FirstOrDefault(u => u.UserTypeId == userTypeGuid);
                //Make sure the Ids match
                Assert.AreEqual(user.Id, updatedUser.Id);
            }
        }
Exemple #29
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test portfolio based on ID and update it
                Guid portfolioGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblPortfolio portfolio = dc.tblPortfolios.FirstOrDefault(p => p.Id == portfolioGuid);

                Guid userGuid = Guid.Parse("88887777-6666-5555-4444-333322221111");
                portfolio.UserId = userGuid;

                //Save changes and get it back out
                dc.SaveChanges();
                tblPortfolio updatedPortfolio = dc.tblPortfolios.FirstOrDefault(p => p.UserId == userGuid);
                //Make sure the Ids match
                Assert.AreEqual(portfolio.Id, updatedPortfolio.Id);
            }
        }
Exemple #30
0
        public void Insert(IList <string> SelectedLanguages)
        {
            try
            {
                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    tblProject project = new tblProject()
                    {
                        Id            = Guid.NewGuid(),
                        Name          = Name,
                        Location      = Location,
                        Filepath      = Filepath,
                        PrivacyId     = PrivacyId,
                        Image         = Image,
                        Description   = Description,
                        UserId        = UserId,
                        DateCreated   = DateCreated,
                        Purpose       = Purpose,
                        Environment   = Environment,
                        Challenges    = Challenges,
                        FuturePlans   = FuturePlans,
                        Collaborators = Collaborators,
                        LastUpdated   = LastUpdated,
                        SoftwareUsed  = SoftwareUsed,
                        StatusId      = StatusId
                    };
                    //Save the Id
                    this.Id = project.Id;

                    dc.tblProjects.Add(project);
                    dc.SaveChanges();
                    foreach (var pl in SelectedLanguages)
                    {
                        ProjectLanguage projlang = new ProjectLanguage();
                        projlang.ProjectId  = project.Id;
                        projlang.LanguageId = (Guid.Parse(pl));
                        projlang.Insert();
                    }
                }
            }
            catch (Exception ex) { throw ex; }
        }