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 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 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 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 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 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 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 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 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 string updateProfilePicture(int userID, int photoID) { renoRatorDBEntities db = new renoRatorDBEntities(); User u = db.Users.FirstOrDefault(a => a.userID == userID); u.profilePhotoID = photoID; db.SaveChanges(); return u.photo.thumbPath; }
public void Save() { renoRatorDBEntities db = new renoRatorDBEntities(); // salt and hash the password string salt = PasswordFunctions.CreateSalt(8); this.salt = salt; this.password = PasswordFunctions.CreateHash(this.password, salt); // add user to the database and save db.AddToUsers(this); db.SaveChanges(); }
public void updateGalleryID() { renoRatorDBEntities db = new renoRatorDBEntities(); JobAd ad = db.JobAds.FirstOrDefault(a => a.jobAdID == this.jobAdID); ad.galleryID = this.galleryID; db.SaveChanges(); }
public void updateGalleryID() { renoRatorDBEntities db = new renoRatorDBEntities(); User u = db.Users.FirstOrDefault(a => a.userID == this.userID); u.profileGalleryID = this.profileGalleryID; db.SaveChanges(); }
public void Save() { renoRatorDBEntities db = new renoRatorDBEntities(); db.AddToReviewComments(this); db.SaveChanges(); }
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 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); }