Beispiel #1
0
        public ActionResult Create(ProjectPrivaciesUserStatuses ppus, string returnurl)
        {
            //double check authentication
            if (Authenticate.IsAuthenticated())
            {
                try
                {
                    PrivacyList plist = new PrivacyList();
                    plist.Load();
                    ppus.Privacies = plist;
                    StatusList slist = new StatusList();
                    slist.Load();
                    ppus.Statuses = slist;
                    if (ppus.SelectedLanguages == null)
                    {
                        ppus.SelectedLanguages = new List <string>();
                    }
                    ProjectList Projects  = new ProjectList();
                    User        userin    = System.Web.HttpContext.Current.Session["user"] as User;
                    string      username  = userin.Username;
                    string      strUserID = userin.Id.ToString();
                    ppus.Project.UserId    = userin.Id;
                    ppus.Project.UserEmail = userin.Email;

                    Projects.LoadbyUser(userin);

                    if (ppus.Project.Name == null)
                    {
                        ModelState.AddModelError(string.Empty, "Project requires a name!");
                    }
                    else
                    {
                        foreach (Project p in Projects)
                        {
                            if (ppus.Project.Name == p.Name)
                            {
                                ModelState.AddModelError(string.Empty, "Project name already exists!");
                            }
                        }

                        if (ppus.DateCreated == null)
                        {
                            ModelState.AddModelError(string.Empty, "Date Created required!");
                        }
                        else if (ppus.LastUpdated == null)
                        {
                            ppus.LastUpdated = ppus.DateCreated;
                        }
                    }

                    UploadedImage ui = new UploadedImage
                    {
                        FilePath   = ppus.Project.Image,
                        Fileupload = ppus.Fileupload,
                        UserName   = username,
                        ObjectType = "Project",
                        ObjectName = ppus.Project.Name
                    };

                    UploadedZip uz = new UploadedZip
                    {
                        FilePath    = ppus.Project.Filepath,
                        Fileupload  = ppus.Fileupload,
                        UserName    = username,
                        ProjectName = ppus.Project.Name
                    };

                    if (!ModelState.IsValid)
                    {
                        ppus.User = new User();
                        ppus.SelectedLanguages  = new List <string>();
                        ppus.AvailableLanguages = new List <SelectListItem>();
                        ppus.Languages          = new LanguageList();
                        ppus.Language           = new Language();
                        ppus.ProjectLanguage    = new ProjectLanguage();
                        ppus.ProjectLanguages   = new ProjectLanguageList();
                        ppus.User.LoadById(userin.Id);
                        ppus.Languages.Load();
                        ppus.AvailableLanguages = GetLanguages(ppus.Languages);
                        return(View(ppus));
                    }

                    string fp = ui.Upload();
                    // fp will return null if no upload file was choosen else use upload file to save to database
                    if (fp != null)
                    {
                        ppus.Project.Image = fp;
                    }
                    else
                    {
                        ppus.Project.Image = null;
                    }

                    fp = uz.Upload();
                    // fp will return null if no upload file was choosen else use upload file to save to database
                    if (fp != null)
                    {
                        ppus.Project.Filepath = fp;
                    }
                    else
                    {
                        ppus.Project.Filepath = null;
                    }

                    ppus.Project.Insert(ppus.SelectedLanguages);
                    return(RedirectToAction("EditProjects", "UserProfile", new { returnurl = HttpContext.Request.Url }));
                }
                catch { return(View(ppus)); }
            }
            else
            {
                return(RedirectToAction("Index", "Login", new { returnurl = HttpContext.Request.Url }));
            }
        }
        public ActionResult EditProject(Guid id, ScreenshotProjects ppus)
        {
            if (Authenticate.IsAuthenticated())
            {
                try
                {
                    ppus.Language  = new Language();
                    ppus.Languages = new LanguageList();

                    if (ppus.SelectedLanguages == null)
                    {
                        ppus.SelectedLanguages = new List <string>();
                    }

                    if (ppus.AvailableLanguages == null)
                    {
                        ppus.AvailableLanguages = new List <SelectListItem>();
                        if (ppus.Languages.Count < 1)
                        {
                            //Load Languages
                            ppus.Languages.Load();
                        }
                        else
                        {
                            // Languages already loaded
                        }
                        ppus.AvailableLanguages = GetLanguages(ppus.Languages);
                    }

                    PrivacyList plist = new PrivacyList();
                    plist.Load();
                    ppus.Privacies = plist;
                    StatusList slist = new StatusList();
                    slist.Load();

                    ppus.ProjectLanguage  = new ProjectLanguage();
                    ppus.ProjectLanguages = new ProjectLanguageList();
                    ppus.Statuses         = slist;
                    ppus.ScreenshotList   = new ScreenshotList();
                    ppus.ScreenshotList.LoadbyProjectID(id);
                    ppus.ProjectId = id;

                    // Deletes all languages associated with project currently
                    ppus.ProjectLanguages.LoadByProjectId(id);
                    foreach (ProjectLanguage pl in ppus.ProjectLanguages)
                    {
                        pl.Delete();
                    }

                    // Insert New languages parsed from input into ProjectLanguage table
                    foreach (var pl in ppus.SelectedLanguages)
                    {
                        ProjectLanguage projlang = new ProjectLanguage();
                        ppus.ProjectLanguage.ProjectId  = id;
                        ppus.ProjectLanguage.LanguageId = (Guid.Parse(pl));
                        ppus.ProjectLanguage.Insert();
                    }

                    User        userin   = System.Web.HttpContext.Current.Session["user"] as User;
                    ProjectList Projects = new ProjectList();
                    Projects.LoadbyUser(userin);
                    string username  = userin.Username;
                    string strUserID = userin.Id.ToString();

                    if (ppus.Project.Name == null)
                    {
                        ModelState.AddModelError(string.Empty, "Project requires a name!");
                    }
                    else
                    {
                        foreach (Project p in Projects)
                        {
                            if (ppus.Project.Name == p.Name)
                            {
                                if (ppus.Project.Id != p.Id)
                                {
                                    ModelState.AddModelError(string.Empty, "Another project already exists with this name!");
                                }
                            }
                        }

                        if (ppus.DateCreated == null)
                        {
                            ModelState.AddModelError(string.Empty, "Date Created required!");
                        }
                        else if (ppus.LastUpdated == null)
                        {
                            ppus.LastUpdated = ppus.DateCreated;
                        }
                    }
                    UploadedZip zu = new UploadedZip
                    {
                        FilePath    = ppus.Project.Filepath,
                        Fileupload  = ppus.ZipFileupload,
                        UserName    = username,
                        ProjectName = ppus.Project.Name
                    };
                    UploadedImage ui = new UploadedImage
                    {
                        FilePath   = ppus.Project.Image,
                        Fileupload = ppus.Fileupload,
                        UserName   = username,
                        ObjectType = "Project",
                        ObjectName = ppus.Project.Name
                    };


                    if (!ModelState.IsValid)
                    {
                        ppus.Languages          = new LanguageList();
                        ppus.SelectedLanguages  = new List <string>();
                        ppus.AvailableLanguages = new List <SelectListItem>();
                        ppus.Privacies          = new PrivacyList();
                        ppus.Statuses           = new StatusList();
                        ppus.User = new User();
                        ppus.User.LoadById(userin.Id);
                        ppus.Privacies.Load();
                        ppus.Statuses.Load();
                        ppus.Languages.Load();
                        ppus.AvailableLanguages = GetLanguages(ppus.Languages);
                        return(View(ppus));
                    }
                    string fp = ui.Upload();
                    string zp = zu.Upload();
                    // fp will return null if no upload file was choosen else use upload file to save to database
                    if (fp != null)
                    {
                        ppus.Project.Image = fp;
                    }
                    else
                    {
                        ppus.Project.Image = null;
                    }

                    if (zp != null)
                    {
                        ppus.Project.Filepath = zp;
                    }
                    else
                    {
                        ppus.Project.Filepath = null;
                    }

                    ppus.Project.DateCreated = ppus.DateCreated;
                    ppus.Project.LastUpdated = ppus.LastUpdated;
                    ppus.Project.Update();
                    return(RedirectToAction("EditProjects", "UserProfile"));
                }
                catch { return(View(ppus)); }
            }
            else
            {
                return(RedirectToAction("Index", "Login", new { returnurl = HttpContext.Request.Url }));
            }
        }
        public ActionResult Create(PortfolioUsers pu)
        {
            //double check authentication
            if (Authenticate.IsAuthenticated())
            {
                try
            {
                    pu.Privacies = new PrivacyList();
                    pu.Privacies.Load();

                    
                    PortfolioList portfolios = new PortfolioList();
                    User userin = System.Web.HttpContext.Current.Session["user"] as User;
                    string username = userin.Username;
                    pu.Portfolio.UserId = userin.Id;
                    pu.Portfolio.UserEmail = userin.Email;
                    portfolios.LoadbyUser(userin);

                    if (pu.Portfolio.Name == null)
                    {
                        ModelState.AddModelError(string.Empty, "Portfolio requires a name!");
                    }
                    else
                    {
                        foreach (Portfolio p in portfolios)
                        {
                            if (pu.Portfolio.Name == p.Name)
                            {
                                ModelState.AddModelError(string.Empty, "Portfolio name already exists!");
                            }
                        }
                    }

                    UploadedImage ui = new UploadedImage
                    {
                        FilePath = pu.Portfolio.PortfolioImage,
                        Fileupload = pu.Fileupload,
                        UserName = username,
                        ObjectType = "Portfolio",
                        ObjectName = pu.Portfolio.Name
                    };

                    string fp = ui.Upload();

                    // fp will return null if no upload file was choosen else use upload file to save to database
                    if (fp != null)
                    {
                        pu.Portfolio.PortfolioImage = fp;
                    }
                    else
                    {
                        // I honestly don't know when this would happen but just in case
                        ModelState.AddModelError(string.Empty, "Portfolio Image could not found");
                    }
                    

                    if (!ModelState.IsValid)
                    {
                        pu.Portfolio = new Portfolio();
                        pu.User = new User();
                        pu.Privacies = new PrivacyList();
                        pu.Privacies.Load();
                        pu.User.LoadById(userin.Id);
                        return View(pu);
                    }

                    pu.Portfolio.Insert();
                    return RedirectToAction("EditPortfolios", "UserProfile", new { returnurl = HttpContext.Request.Url });
                }
            catch { return View(pu); }
            }
            else
            {
                return RedirectToAction("Index", "Login", new { returnurl = HttpContext.Request.Url });
            }
        }
        public ActionResult EditPortfolio(Guid id, UserProfile up)
        {
            if (Authenticate.IsAuthenticated())
            {
                try
                {
                    User          userin     = System.Web.HttpContext.Current.Session["user"] as User;
                    PortfolioList Portfolios = new PortfolioList();
                    Portfolios.LoadbyUser(userin);
                    up.Portfolios = Portfolios;
                    ProjectList projects = new ProjectList();
                    projects.LoadbyPortfolioID(id);
                    PrivacyList privacies = new PrivacyList();
                    privacies.Load();
                    up.Privacies = privacies;
                    up.Projects  = projects;
                    string username = userin.Username;

                    if (up.Portfolio.Name == null)
                    {
                        ModelState.AddModelError(string.Empty, "Portfolio requires a name!");
                    }
                    else
                    {
                        foreach (Portfolio p in Portfolios)
                        {
                            if (up.Portfolio.Name == p.Name)
                            {
                                if (up.Portfolio.Id != p.Id)
                                {
                                    ModelState.AddModelError(string.Empty, "Another portfolio already exists with this name!");
                                }
                            }
                        }
                    }
                    UploadedImage ui = new UploadedImage
                    {
                        FilePath   = up.Portfolio.PortfolioImage,
                        Fileupload = up.Fileupload,
                        UserName   = username,
                        ObjectType = "Portfolio",
                        ObjectName = up.Portfolio.Name
                    };

                    string fp = ui.Upload();

                    // fp will return null if no upload file was choosen else use upload file to save to database
                    if (fp != null)
                    {
                        up.Portfolio.PortfolioImage = fp;
                    }
                    else
                    {
                        up.Portfolio.PortfolioImage = null;
                    }

                    if (!ModelState.IsValid)
                    {
                        up.Privacies = new PrivacyList();
                        up.User      = new User();
                        up.User.LoadById(userin.Id);
                        up.Privacies.Load();
                        up.Projects.LoadbyPortfolioID(up.Portfolio.Id);
                        return(View(up));
                    }
                    up.Portfolio.Update();
                    return(RedirectToAction("EditPortfolios"));
                }
                catch { return(View(up)); }
            }
            else
            {
                return(RedirectToAction("Index", "Login", new { returnurl = HttpContext.Request.Url }));
            }
        }
Beispiel #5
0
        public ActionResult Index(UserUserTypes uut)
        {
            try
            {
                UploadedImage ui = new UploadedImage();
                if (uut.User.Email == null)
                {
                    ModelState.AddModelError(string.Empty, "Email address is required");
                }

                else if (uut.User.CheckIfEmailExists(uut.User.Email) == true)
                {
                    ModelState.AddModelError(string.Empty, "Email Already Exists");
                }

                if (uut.User.CheckIfUsernameExists(uut.User.Username) != Guid.Empty)
                {
                    ModelState.AddModelError(string.Empty, "Username Already Exists");
                }
                else
                {
                    ui.FilePath   = uut.User.ProfileImage;
                    ui.Fileupload = uut.Fileupload;
                    ui.UserName   = uut.User.Username;
                    ui.ObjectType = "Profile";
                    ui.ObjectName = null;
                }

                if (uut.User.FirstName == null)
                {
                    ModelState.AddModelError(string.Empty, "First Name is required");
                }

                if (uut.User.LastName == null)
                {
                    ModelState.AddModelError(string.Empty, "Last Name is required");
                }

                if (uut.User.Password == null)
                {
                    ModelState.AddModelError(string.Empty, "Password is required");
                }

                else if (uut.User.Password.Length < 6)
                {
                    ModelState.AddModelError(string.Empty, "Password needs to be at least 6 characters");
                }
                else if (uut.User.Password.Length > 16)
                {
                    ModelState.AddModelError(string.Empty, "Password needs to be less than 16 characters");
                }
                else if (uut.ConfirmPassword != uut.User.Password)
                {
                    ModelState.AddModelError(string.Empty, "Passwords did not match");
                }
                // TODO:
                // ADD VALIDATION FOR EMPLOYER?

                if (!ModelState.IsValid)
                {
                    uut.UserTypes = new UserTypeList();
                    uut.UserTypes.LoadNonAdmin();
                    return(View(uut));
                }

                //Uploads image and returns string value entered in database for image
                string fp = ui.Upload();

                // fp will return null if no upload file was choosen else use upload file to save to database
                if (fp != null)
                {
                    uut.User.ProfileImage = fp;
                }
                else
                {
                    uut.User.ProfileImage = null;
                }


                //Success, insert and redirect to the login!
                uut.User.Insert();
                return(RedirectToAction("Index", "Login"));
            }
            catch
            {
                uut.UserTypes = new UserTypeList();
                uut.UserTypes.LoadNonAdmin();
                return(View(uut));
            }
        }
Beispiel #6
0
        public ActionResult EditProfile(UserProfile up)
        {
            try
            {
                User userin = System.Web.HttpContext.Current.Session["user"] as User;
                FirstName            = up.User.FirstName;
                LastName             = up.User.LastName;
                Email                = up.User.Email;
                UserTypesID          = up.User.UserTypeId;
                UserTypesDescription = up.User.UserTypeDescription;
                ProfileImage         = up.User.ProfileImage;
                Username             = up.User.Username;
                Bio = up.User.Bio;
                User user = new User();
                user.LoadById(userin.Id);
                up.User = user;
                up.User.ProfileImage        = ProfileImage;
                up.User.Username            = Username;
                up.User.Email               = Email;
                up.User.FirstName           = FirstName;
                up.User.LastName            = LastName;
                up.User.UserTypeId          = UserTypesID;
                up.User.UserTypeDescription = UserTypesDescription;
                up.User.Bio = Bio;

                string currentemail    = userin.Email;
                string currentUsername = userin.Username;

                UploadedImage ui = new UploadedImage();
                if (up.User.Username == null)
                {
                    ModelState.AddModelError(string.Empty, "Username is required");
                }
                else if (up.User.Username != currentUsername)
                {
                    if (up.User.CheckIfUsernameExists(up.User.Username) != Guid.Empty)
                    {
                        ModelState.AddModelError(string.Empty, "Username Already Exists");
                    }
                    else
                    {
                        ui.FilePath   = up.User.ProfileImage;
                        ui.Fileupload = up.Fileupload;
                        ui.UserName   = up.User.Username;
                        ui.ObjectType = "Profile";
                        ui.ObjectName = null;
                    }
                }
                else
                {
                    ui.FilePath   = up.User.ProfileImage;
                    ui.Fileupload = up.Fileupload;
                    ui.UserName   = up.User.Username;
                    ui.ObjectType = "Profile";
                    ui.ObjectName = null;
                }

                if (up.User.Email == null)
                {
                    ModelState.AddModelError(string.Empty, "Email address is required");
                }
                else if (up.User.Email != currentemail)
                {
                    if (up.User.CheckIfEmailExists(up.User.Email) == true)
                    {
                        ModelState.AddModelError(string.Empty, "Email Already In Use");
                    }
                }
                //POSSIBLE ADD EMAIL VERIFICATION ON CHANGE EMAIL OR RELOGIN HERE

                if (up.User.FirstName == null)
                {
                    ModelState.AddModelError(string.Empty, "First Name is required");
                }

                if (up.User.LastName == null)
                {
                    ModelState.AddModelError(string.Empty, "Last Name is required");
                }

                if (!ModelState.IsValid)
                {
                    up.UserTypes = new UserTypeList();
                    up.UserTypes.LoadNonAdmin();
                    return(View(up));
                }

                //Uploads image and returns string value entered in database for image
                string fp = ui.Upload();

                // fp will return null if no upload file was choosen else use upload file to save to database
                if (fp != null)
                {
                    up.User.ProfileImage = fp;
                }
                else
                {
                    up.User.ProfileImage = null;
                }
                up.User.Update();

                //TODO: Possible Redirect to confimration or Confirmation message of saved changes here!
                return(RedirectToAction("Index", "UserProfile", new { returnurl = HttpContext.Request.Url }));
            }
            catch
            {
                return(View(up));
            }
            // ==================== END PROFILE EDIT =====================
        }