/// <summary>
 /// Deprecated Method for adding a new object to the JobAds EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToJobAds(JobAd jobAd)
 {
     base.AddObject("JobAds", jobAd);
 }
예제 #2
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);
        }
 /// <summary>
 /// Create a new JobAd object.
 /// </summary>
 /// <param name="jobAdID">Initial value of the jobAdID property.</param>
 /// <param name="userID">Initial value of the userID property.</param>
 /// <param name="addressID">Initial value of the addressID property.</param>
 /// <param name="description">Initial value of the description property.</param>
 /// <param name="targetEndDate">Initial value of the targetEndDate property.</param>
 /// <param name="active">Initial value of the active property.</param>
 public static JobAd CreateJobAd(global::System.Int32 jobAdID, global::System.Int32 userID, global::System.Int32 addressID, global::System.String description, global::System.DateTime targetEndDate, global::System.Boolean active)
 {
     JobAd jobAd = new JobAd();
     jobAd.jobAdID = jobAdID;
     jobAd.userID = userID;
     jobAd.addressID = addressID;
     jobAd.description = description;
     jobAd.targetEndDate = targetEndDate;
     jobAd.active = active;
     return jobAd;
 }