Example #1
0
        public ActionResult Ads()
        {
            //if (Session["userID"] == null)
            //return RedirectToAction("Login", "User", new { redirectPage = "Post", redirectController = "JobAd" });

            _db = new renoRatorDBEntities();
            var ads = (from JobAds1 in _db.JobAds select JobAds1).ToList();

            Dictionary <string, int> tags = new Dictionary <string, int>();

            foreach (var ad in ads)
            {
                string[] allTags = ad.tags.Split('|');
                foreach (string tag in allTags)
                {
                    if (tag != "")
                    {
                        if (!tags.ContainsKey(tag))
                        {
                            tags[tag] = 1;
                        }
                        else
                        {
                            tags[tag]++;
                        }
                    }
                }
            }

            ViewBag.tags = tags;

            return(View(ads));
        }
Example #2
0
        private static int tryLogin(string email, string password)
        {
            renoRatorDBEntities _db = new renoRatorDBEntities();
            var user = _db.Users.Where(u => u.email == email).FirstOrDefault();

            if (user != null && user.password == PasswordFunctions.CreateHash(password, user.salt))
            {
                return(user.userID);
            }
            return(-1);
        }
Example #3
0
        public ActionResult Register(FormCollection form)
        {
            _db = new renoRatorDBEntities();
            var newUser = new RegisterModel();

            //temp
            newUser.userTypeID = 1;

            // Deserialize (Include white list!)
            TryUpdateModel(newUser, new string[] { "fname", "lname", "email", "password" }, form.ToValueProvider());

            // Validate
            if (String.IsNullOrEmpty(newUser.fname))
            {
                ModelState.AddModelError("fname", "First name is required!");
            }
            if (String.IsNullOrEmpty(newUser.lname))
            {
                ModelState.AddModelError("lname", "Last name is required!");
            }
            if (String.IsNullOrEmpty(newUser.email))
            {
                ModelState.AddModelError("email", "Email is required!");
            }
            if (String.IsNullOrEmpty(newUser.password))
            {
                ModelState.AddModelError("password", "Password is required!");
            }
            if (newUser.password != form["passwordConfirm"])
            {
                ModelState.AddModelError("passwordConfirm", "Passwords don't match!");
            }
            if (newUser.email != form["emailConfirm"])
            {
                ModelState.AddModelError("emailConfirm", "Email addresses don't match!");
            }



            // If valid, save movie to database
            if (ModelState.IsValid)
            {
                newUser.Save();
                return(RedirectToAction("Home"));
            }

            // Otherwise, reshow form
            return(View(newUser));
        }
Example #4
0
        public void populateDropdowns()
        {
            _db = new renoRatorDBEntities();
            var priceRanges = from range in _db.PriceRanges.ToList()
                              select new { priceRangeID = range.priceRangeID, range = range.min + " - " + range.max };
            SelectList priceranges = new SelectList(priceRanges.ToArray(), "priceRangeID", "range");

            ViewBag.priceranges = priceranges;

            var        citiesList = _db.Cities.ToList();
            SelectList cities     = new SelectList(citiesList.ToArray(), "cityID", "city1");

            ViewBag.cities = cities;

            var        provinceList = _db.Provinces.ToList();
            SelectList provinces    = new SelectList(provinceList.ToArray(), "provinceID", "province1");

            ViewBag.provinces = provinces;
        }
Example #5
0
        public void Save()
        {
            var  db      = new renoRatorDBEntities();
            User newUser = new User();

            newUser.userTypeID = this.userTypeID;
            newUser.fname      = this.fname;
            newUser.lname      = this.lname;
            newUser.email      = this.email;
            newUser.password   = this.password;
            if (!String.IsNullOrEmpty(this.bio))
            {
                newUser.bio = this.bio;
            }
            if (this.profileGalleryID > 0)
            {
                newUser.profileGalleryID = this.profileGalleryID;
            }
            if (this.profilePhotoID > 0)
            {
                newUser.profilePhotoID = this.profilePhotoID;
            }
            if (this.addressID > 0)
            {
                newUser.addressID = this.addressID;
            }
            if (this.portfolioGalleryID > 0)
            {
                newUser.portfolioGalleryID = this.portfolioGalleryID;
            }

            // salt and hash the password
            string salt = PasswordFunctions.CreateSalt(8);

            newUser.salt     = salt;
            newUser.password = PasswordFunctions.CreateHash(newUser.password, salt);

            db.AddToUsers(newUser);
            db.SaveChanges();
        }
Example #6
0
        public ActionResult Post(FormCollection form)
        {
            if (Session["userID"] == null)
            {
                return(RedirectToAction("Login", "User", new { redirectPage = "Post", redirectController = "JobAd" }));
            }

            _db = new renoRatorDBEntities();
            var newJobAd = new JobAd();

            newJobAd.address = new Address();

            TryUpdateModel(newJobAd, new string[] { "address.addressLine1", "address.addressLine2", "address.postalCode", "address.cityID" }, form.ToValueProvider());
            List <string> requiredFields = new List <string>()
            {
                "title", "address.addressLine1", "address.city.provinceID", "address.cityID", "priceRangeID", "description", "targetEndDate"
            };

            // check for null fields
            foreach (string field in requiredFields)
            {
                if (String.IsNullOrEmpty(form[field].Trim()))
                {
                    ModelState.AddModelError(field, "Field is required!");
                }
            }

            // validate other fields
            if (!ValidateFunctions.validPostalCode(form["address.postalCode"]))
            {
                ModelState.AddModelError("address.postalCode", "Postal code is invalid!");
            }
            if (!ValidateFunctions.validDateFormat(form["targetEndDate"]))
            {
                ModelState.AddModelError("targetEndDate", "Date format is invalid!");
            }

            try
            {
                newJobAd.address.addressLine1 = form["address.addressLine1"];
                newJobAd.address.addressLine2 = form["address.addressLine2"];
                newJobAd.address.postalCode   = form["address.postalCode"];
                newJobAd.address.cityID       = Convert.ToInt32(form["address.cityID"]);
                newJobAd.address.country      = "Canada";

                newJobAd.address.city.provinceID = Convert.ToInt32(form["address.city.provinceID"]);
                newJobAd.userID        = (int)Session["userID"];
                newJobAd.active        = true;
                newJobAd.priceRangeID  = Convert.ToInt32(form["priceRangeID"]);
                newJobAd.tags          = form["tags"].Replace(",", "||");
                newJobAd.description   = form["description"];
                newJobAd.targetEndDate = Convert.ToDateTime(form["targetEndDate"]);
                newJobAd.title         = form["title"];
            }
            catch { }



            if (ModelState.IsValid)
            {
                _db.AddToJobAds(newJobAd);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            // Otherwise, reshow form
            TryUpdateModel(newJobAd);
            populateDropdowns();
            return(View(newJobAd));
        }