public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { using (photoshareEntities dbContext = new photoshareEntities()) { try { /*JUST TO SHOW I CAN WRITE SQL QUERIES AS WELL :) */ var @sqlAuthenticateUser = "******" + "users AS u ON m.membership_id = u.membership_id " + "WHERE m.username={0} AND m.password={1} LIMIT 0,1"; var isAuthenticUser = dbContext.memberships. SqlQuery(sqlAuthenticateUser, model.UserName, model.Password).SingleOrDefault(); if (isAuthenticUser == null) { ModelState.AddModelError("", "The user name or password provided is incorrect."); } else { Session.Add("LoggedInUser", isAuthenticUser.username); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Photo"); } } } catch (Exception ex) { ModelState.AddModelError("UNKNOWN_ERROR", ex.Message); } } } // If we got this far, something failed, redisplay form return View(model); }
protected user GetUser(string username) { user _user = null; using (photoshareEntities db = new photoshareEntities()) { var _u = (from u in db.users join m in db.memberships on u.membership_id equals m.membership_id where m.username == username select u).FirstOrDefault(); _user = _u as user; } return _user; }
/// <summary> /// Gets the current logged in user by checking session variables /// </summary> /// <returns>A currently logged in user </returns> protected user GetLoggedUser() { if (Session["LoggedInUser"] == null) { return null; } user _loggedInUser = null; using (photoshareEntities db = new photoshareEntities()) { var username = Session["LoggedInUser"].ToString(); var loggedInUser = (from u in db.users join m in db.memberships on u.membership_id equals m.membership_id where m.username == username select u).FirstOrDefault(); _loggedInUser = loggedInUser as user; } return _loggedInUser; }
public ActionResult GenerateFakePhotos() { List<user> users; using (var db2 = new photoshareEntities()) { users = db2.users.ToList(); } foreach (user u in users) { using (TransactionScope scope = new TransactionScope()) { for (int i = 0; i < 10; i++) { int cat_id = new Random().Next(1, 21); int randDays = new Random().Next(1, 28); photo p = new photo { uploaded_date = DateTime.Now.AddMonths(-1).AddDays(randDays), description = RandomString(200), name = RandomString(10), photo_category = cat_id, tags = RandomString(5) + "," + RandomString(5) + "," + RandomString(5), user_id = u.id, views_count = 0, photo_url_o = string.Format("/Images/Uploads/{0}/{1}.jpg", u.id.ToString(), (i + 1).ToString() + "_L"), photo_url_m = string.Format("/Images/Uploads/{0}/{1}.jpg", u.id.ToString(), (i + 1).ToString() + "_M"), photo_url_s = string.Format("/Images/Uploads/{0}/{1}.jpg", u.id.ToString(), (i + 1).ToString() + "_S") }; db.photos.Add(p); } db.SaveChanges(); scope.Complete(); } } return RedirectToAction("Index", "User"); }
//F/5,6 public ActionResult UploadFakeExif() { List<photo> _photos; using (var db2 = new photoshareEntities()) { _photos = db2.photos.ToList(); } foreach (photo p in _photos) { if (p.id == 347 || p.id == 350) { } else { exif_data _exif = new exif_data { aperture = "F/" + new Random().Next(3, 22).ToString(), camera = "Nikon D7000", date_taken = DateTime.Now.AddYears(-2). AddDays(new Random().Next(1, 360)).ToLongDateString(), focal_length = new Random().Next(18, 300).ToString(), iso = new Random().Next(100, 1600).ToString(), shutter_speed = "1/" + new Random().Next(1, 4000).ToString(), photo_id = p.id }; db.exif_data.Add(_exif); db.SaveChanges(); } } return RedirectToAction("Index"); }
public ActionResult UplaodFakePhoto() { List<user> users; using (var db2 = new photoshareEntities()) { users = db2.users.ToList(); } foreach (user u in users) { if (u.id >= 91 && u.id < 93) { DirectoryInfo di = new DirectoryInfo(Server.MapPath(string.Format("~/Images/Uploads/{0}/", u.id.ToString()))); int i = 1; foreach (FileInfo file in di.GetFiles("*")) { var fileName = Path.GetFileNameWithoutExtension(file.Name); var fileExt = Path.GetExtension(file.Name); var destinationDirectory = Path.Combine(Server.MapPath("~/Images/Uploads/"), u.id.ToString()); var newFileTemp = i.ToString(); var newFileName = newFileTemp + "_L" + fileExt; var path = Path.Combine(destinationDirectory, newFileName); file.CopyTo(path, true); var thumbMedium = newFileTemp + "_M" + fileExt; CreateThumbnail(path, ImageSize.Medium, Path.Combine(destinationDirectory, thumbMedium)); var thumbSmall = newFileTemp + "_S" + fileExt; CreateThumbnail(path, ImageSize.Small, Path.Combine(destinationDirectory, thumbSmall)); i++; GC.Collect(); } GC.Collect(); } else { continue; } } return RedirectToAction("Index", "User"); }