public int updateGallery() { renoRatorDBEntities db = new renoRatorDBEntities(); Gallery g = db.Galleries.FirstOrDefault(gal => gal.galleryID == this.galleryID); if (g == null) g = new Gallery(); int gid = g.galleryID; //g.photos = this.photos; g.name = this.name; if (gid == 0) db.AddToGalleries(g); db.SaveChanges(); int newid = g.galleryID; foreach (Photo p in this.photos) { Photo photo = new Photo(); photo.galleryID = newid; photo.path = p.path; photo.thumbPath = p.thumbPath; photo.description = p.description; db.AddToPhotos(photo); db.SaveChanges(); } return newid; }
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); }
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); }
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(); }
public static IQueryable<Job> getJobsByContractorID(int id) { renoRatorDBEntities _db = new renoRatorDBEntities(); return from j in _db.Jobs where j.contractorUserID == id orderby j.jobID select j; }
public static bool deleteJobForContractor(int id, int contractorID) { renoRatorDBEntities _db = new renoRatorDBEntities(); var job = _db.Jobs.Where(j => j.jobID == id && contractorID == j.contractorUserID).FirstOrDefault(); if(job != null) _db.Jobs.DeleteObject(job); return _db.SaveChanges() > 0; }
public void addProfileGallery() { try { renoRatorDBEntities db = new renoRatorDBEntities(); User user = db.Users.FirstOrDefault(a => a.userID == this.userID); user.profileGalleryID = this.profileGalleryID; db.SaveChanges(); } catch { } }
public void addGallery() { try { renoRatorDBEntities db = new renoRatorDBEntities(); JobAd ad = db.JobAds.FirstOrDefault(a => a.jobAdID == this.jobAdID); ad.galleryID = this.galleryID; db.SaveChanges(); } catch{ } }
public void deleteSingleAd(int adID) { renoRatorDBEntities db = new renoRatorDBEntities(); JobAd deleteAd = db.JobAds.FirstOrDefault(a => a.jobAdID == adID); try { deleteAd.active = false; db.SaveChanges(); } catch { } }
public void getGallery(int id) { try { renoRatorDBEntities db = new renoRatorDBEntities(); Gallery g = db.Galleries.FirstOrDefault(gal => gal.galleryID == id); this.galleryID = g.galleryID; this.photos = g.photos; this.name = g.name; } catch { } }
public void Save() { renoRatorDBEntities db = new renoRatorDBEntities(); db.AddToReviews(this); foreach(double[] r in this.ratings) { ReviewRating rating = new ReviewRating(); rating.reviewID = this.reviewID; rating.ratingQuestionID = Convert.ToInt32(r[0]); rating.rating = r[1]; db.AddToReviewRatings(rating); } db.SaveChanges(); }
public void Save() { renoRatorDBEntities db = new renoRatorDBEntities(); this.address.city = db.Cities.Where(c => c.cityID == this.address.cityID).FirstOrDefault(); this.address.country = "Canada"; this.address.postalCode = this.address.postalCode.Replace(" ", "").Replace("-", "").Trim(); List<string> tagList = new List<string>(); if (this.tags != null) { foreach (String tag in this.tags.Split(',')) tagList.Add(tag.Trim().ToLower()); this.tags = string.Join("|", tagList); } db.AddToJobs(this); db.SaveChanges(); }
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; }
public void deleteSinglePhoto(int photoid, string folderLocation) { try { renoRatorDBEntities db = new renoRatorDBEntities(); Photo p = db.Photos.FirstOrDefault(ph => ph.photoID == photoid); string path = folderLocation + p.path.Substring(16); string thumbPath = folderLocation + p.thumbPath.Substring(16); // delete actual file from server System.IO.File.Delete(path); System.IO.File.Delete(thumbPath); db.DeleteObject(p); db.SaveChanges(); } catch { } }
public void deleteSingleMessage(int userID, int msgID) { renoRatorDBEntities db = new renoRatorDBEntities(); message deleteMSG = db.messages.FirstOrDefault(m => m.messageID == msgID); bool is_sender = deleteMSG.senderID == userID; bool is_receiver = deleteMSG.receiverID == userID; if (!is_sender && !is_receiver) return; try { if (is_sender) deleteMSG.deletedBySender = true; if (is_receiver) deleteMSG.deletedByReceiver = true; db.SaveChanges(); } catch { } }
public List<User> getAllContractors(FormCollection form) { string fname = form["fname"].ToString(); string lname = form["lname"].ToString(); string company = form["company"].ToString(); int city = (form["city"] == "") ? 0 : Convert.ToInt32(form["city"]); int province = (form["province"] == "") ? 0 : Convert.ToInt32(form["province"].ToString()); renoRatorDBEntities db = new renoRatorDBEntities(); var qry = (from u in db.Users where u.userTypeID == 2 && u.fname.Contains(fname) && u.lname.Contains(lname) && u.company.Contains(company) select u); if (city > 0 && province > 0) return qry.Where(u => u.address.city.cityID == city && u.address.city.province.provinceID == province).OrderBy(u => u.userID).ToList(); else if (city > 0) return qry.Where(u => u.address.city.cityID == city).OrderBy(u => u.userID).ToList(); else if (province > 0) return qry.Where(u => u.address.city.province.provinceID == province).OrderBy(u => u.userID).ToList(); else return qry.OrderBy(u => u.userID).ToList(); }
public int countAllSentMessages(int userID) { renoRatorDBEntities db = new renoRatorDBEntities(); return (from m in db.messages where m.senderID == userID && m.deletedBySender == false select m).Count(); }
public static List<JobAd> getAllAdsAsList() { renoRatorDBEntities db = new renoRatorDBEntities(); return (from j in db.JobAds where j.active == true orderby j.jobAdID select j).ToList(); }
public List<RatingQuestion> getQuestions() { renoRatorDBEntities db = new renoRatorDBEntities(); List<RatingQuestion> result = db.RatingQuestions.ToList(); return result; }
public IEnumerable<RatingQuestion> getAllRatingQuestions() { renoRatorDBEntities db = new renoRatorDBEntities(); return (from q in db.RatingQuestions select q); }
public void setMessageRead(int userID, int msgID) { renoRatorDBEntities db = new renoRatorDBEntities(); message msg = db.messages.FirstOrDefault(m => m.messageID == msgID); if (msg != null) { if (!msg.is_read && msg.receiverID == userID) { msg.is_read = true; db.SaveChanges(); } } }
public void Save() { renoRatorDBEntities db = new renoRatorDBEntities(); this.msgDate = DateTime.Now; this.deletedByReceiver = false; this.deletedBySender = false; db.AddTomessages(this); db.SaveChanges(); }
public message getSingleMessage(int id) { renoRatorDBEntities db = new renoRatorDBEntities(); return (from m in db.messages select m).FirstOrDefault(m => m.messageID == id); }
public IEnumerable<message> getAllSentMessagesDesc(int userID) { renoRatorDBEntities db = new renoRatorDBEntities(); return (from m in db.messages where m.senderID == userID && m.deletedBySender == false orderby m.msgDate descending select m); }
public IEnumerable<message> getAllReceivedMessages(int userID) { renoRatorDBEntities db = new renoRatorDBEntities(); return (from m in db.messages where m.receiverID == userID && m.deletedByReceiver == false select m); }
public static IQueryable<JobAd> getAllAdsWithTag(string tag) { renoRatorDBEntities db = new renoRatorDBEntities(); return (from j in db.JobAds where j.active == true && j.tags != null && j.tags.Contains(tag) orderby j.jobAdID select j); }
public static IQueryable<message> getAllMessages() { renoRatorDBEntities db = new renoRatorDBEntities(); return (from m in db.messages select m); }
public int update() { try { renoRatorDBEntities db = new renoRatorDBEntities(); JobAd ad = db.JobAds.FirstOrDefault(a => a.jobAdID == this.jobAdID); this.address.city = db.Cities.Where(c => c.cityID == this.address.cityID).FirstOrDefault(); this.address.country = "Canada"; this.address.postalCode = this.address.postalCode.Replace(" ", "").Replace("-", "").Trim(); List<string> tagList = new List<string>(); if (this.tags != null) { foreach (String tag in this.tags.Split(',')) tagList.Add(tag.Trim().ToLower()); this.tags = string.Join("|", tagList); } this.targetEndDate = this.targetEndDate.Date; ad.title = this.title; ad.address.city = this.address.city; ad.address.postalCode = this.address.postalCode; ad.targetEndDate = this.targetEndDate; ad.tags = this.tags; ad.address.addressLine1 = this.address.addressLine1; ad.address.addressLine2 = this.address.addressLine2; ad.priceRangeID = this.priceRangeID; ad.description = this.description; //ad.galleryID = this.galleryID; int rowsUpdated = db.SaveChanges(); return rowsUpdated; } catch { return 0; } }
public static IQueryable<JobAd> getAllAdsWithUserID(int user) { renoRatorDBEntities db = new renoRatorDBEntities(); return (from j in db.JobAds where j.active == true && j.userID == user orderby j.jobAdID select j); }
public static JobAd getSingleJobAd(int id) { renoRatorDBEntities db = new renoRatorDBEntities(); return db.JobAds.FirstOrDefault(j => j.jobAdID == id); }