public ActionResult Index() { InterestIdentityViewBags(); var model = new FindUsersModel(); LoadFilteredUsers(false, model); ViewBag.FilteredUsers = _uas.ToUnorderdList; var rle = new Role(SiteEnums.RoleTypes.cyber_girl.ToString()); IList<UserAccount> girlModels = UserAccountRole.GetUsersInRole(rle.RoleID); if (girlModels == null || girlModels.Count <= 0) return View(model); girlModels.Shuffle(); UserAccount featuredModel = girlModels[0]; var featuredPhoto = new UserAccountDetail(); featuredPhoto.GetUserAccountDeailForUser(featuredModel.UserAccountID); int photoNumber = Utilities.RandomNumber(1, 4); string photoPath = featuredPhoto.FullProfilePicURL; if (photoNumber > 1) { var ups = new UserPhotos(); ups.GetUserPhotos(featuredModel.UserAccountID); if (ups.Count > 0) { foreach (UserPhoto up1 in ups.Where(up1 => (up1.RankOrder + 1) == photoNumber)) { photoPath = up1.FullProfilePicURL; break; } } } string[] colorBorder = GeneralConfigs.RandomColors.Split(','); var rnd = new Random(); string[] myRandomArray = colorBorder.OrderBy(x => rnd.Next()).ToArray(); ViewBag.FeaturedModel = string.Format(@" <a class=""m_over"" href=""{1}""> <img src=""{0}"" class=""featured_user"" style="" border: 2px dashed {2}; "" /></a>", photoPath, featuredModel.UrlTo, myRandomArray[0]); return View(model); }
public ActionResult EditPhoto(HttpPostedFileBase file) { mu = Membership.GetUser(); UserPhoto up1 = null; int swapID = 0; var acl = CannedAcl.PublicRead; S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; if (Request.Form["new_default"] != null && int.TryParse(Request.Form["new_default"], out swapID)) { // swap the default with the new default uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey)); string currentDefaultMain = uad.ProfilePicURL; string currentDefaultMainThumb = uad.ProfileThumbPicURL; up1 = new UserPhoto(swapID); uad.ProfilePicURL = up1.PicURL; uad.ProfileThumbPicURL = up1.ThumbPicURL; uad.LastPhotoUpdate = DateTime.UtcNow; uad.Update(); up1.PicURL = currentDefaultMain; up1.ThumbPicURL = currentDefaultMainThumb; up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); up1.Update(); LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey)); return View(uad); } string photoOne = "photo_edit_1"; string photoTwo = "photo_edit_2"; string photoThree = "photo_edit_3"; LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey)); uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey)); if (file == null) { ViewBag.IsValid = false; ModelState.AddModelError(string.Empty, BootBaronLib.Resources.Messages.NoFile); return View(uad); } string photoEdited = Request.Form["photo_edit"]; string mainPhotoToDelete = string.Empty; string thumbPhotoToDelete = string.Empty; ups = new UserPhotos(); ups.GetUserPhotos(uad.UserAccountID); if (string.IsNullOrEmpty(uad.ProfilePicURL) || ups.Count == 2 && photoEdited == photoOne) { mainPhotoToDelete = uad.ProfilePicURL; thumbPhotoToDelete = uad.ProfileThumbPicURL; } else { if (ups.Count > 1 && photoEdited == photoTwo) { up1 = new UserPhoto(ups[0].UserPhotoID); up1.RankOrder = 1; mainPhotoToDelete = up1.PicURL; thumbPhotoToDelete = up1.ThumbPicURL; } else if (ups.Count > 1 && photoEdited == photoThree) { up1 = new UserPhoto(ups[1].UserPhotoID); up1.RankOrder = 2; mainPhotoToDelete = ups[1].FullProfilePicURL; thumbPhotoToDelete = up1.ThumbPicURL; } } if (!string.IsNullOrEmpty(mainPhotoToDelete)) { // delete the existing photos try { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, mainPhotoToDelete); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, thumbPhotoToDelete); } } catch { // whatever } } Bitmap b = new Bitmap(file.InputStream); // full System.Drawing.Image fullPhoto = (System.Drawing.Image)b; fullPhoto = ImageResize.FixedSize(fullPhoto, 300, 300, System.Drawing.Color.Black); string fileNameFull = Utilities.CreateUniqueContentFilename(file); Stream maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, file.ContentType, acl); if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) || ups.Count == 2 && photoEdited == photoOne) { uad.ProfilePicURL = fileNameFull; } else { if (up1 == null) { up1 = new UserPhoto(); } up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey); up1.PicURL = fileNameFull; if ((ups.Count > 0 && photoEdited == photoTwo) || (ups.Count == 0)) { up1.RankOrder = 1; } else if ((ups.Count > 1 && photoEdited == photoThree) || ups.Count == 1) { up1.RankOrder = 2; } if (ups.Count == 1 && ups[0].RankOrder == 2) { ups[0].RankOrder = 1; ups[0].Update(); } } fullPhoto = (System.Drawing.Image)b; fullPhoto = ImageResize.FixedSize(fullPhoto, 75, 75, System.Drawing.Color.Black); fileNameFull = Utilities.CreateUniqueContentFilename(file); maker = fullPhoto.ToAStream(ImageFormat.Jpeg); s3.AddObject( maker, maker.Length, AmazonCloudConfigs.AmazonBucketName, fileNameFull, file.ContentType, acl); //// thumb if (string.IsNullOrEmpty(uad.ProfileThumbPicURL) || ups.Count == 2 && photoEdited == photoOne) { uad.ProfileThumbPicURL = fileNameFull; uad.LastPhotoUpdate = DateTime.UtcNow; uad.Set(); } else { up1.UserAccountID = Convert.ToInt32(mu.ProviderUserKey); up1.ThumbPicURL = fileNameFull; if ( (ups.Count == 0 && photoEdited == photoTwo) || (ups.Count > 0 && photoEdited == photoTwo) ) { up1.RankOrder = 1; } else if ( (ups.Count == 0 && photoEdited == photoThree) || (ups.Count > 1 && photoEdited == photoThree) ) { up1.RankOrder = 2; } } b.Dispose(); if (up1 != null && up1.UserPhotoID == 0) { up1.CreatedByUserID = Convert.ToInt32(mu.ProviderUserKey); up1.Create(); } else if (up1 != null && up1.UserPhotoID > 0) { up1.UpdatedByUserID = Convert.ToInt32(mu.ProviderUserKey); up1.Update(); } LoadCurrentImagesViewBag(Convert.ToInt32(mu.ProviderUserKey)); return View(uad); }
private void LoadCurrentImagesViewBag(int userAccountID) { UserPhotos ups = new UserPhotos(); ups.GetUserPhotos(userAccountID); if (ups.Count == 0) { UserPhoto up = new UserPhoto(); ups.Add(up); up = new UserPhoto(); ups.Add(up); } else if (ups.Count == 1) { UserPhoto up = new UserPhoto(); up.RankOrder = 2; ups.Add(up); } ViewBag.SecondUserPhotoFull = ups[0].FullProfilePicURL; ViewBag.SecondUserPhotoThumb = ups[0].FullProfilePicThumbURL; ViewBag.SecondUserPhotoID = ups[0].UserPhotoID; ViewBag.ThirdUserPhotoFull = ups[1].FullProfilePicURL; ViewBag.ThirdUserPhotoThumb = ups[1].FullProfilePicThumbURL; ViewBag.ThirdUserPhotoID = ups[1].UserPhotoID; }
public ActionResult EditPhotoDelete() { string str = Request.Form["delete_photo"]; mu = Membership.GetUser(); uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey)); S3Service s3 = new S3Service(); s3.AccessKeyID = AmazonCloudConfigs.AmazonAccessKey; s3.SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey; if (str == "1") { try { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, uad.ProfilePicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, uad.ProfilePicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, uad.ProfileThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, uad.ProfileThumbPicURL); } } catch { // whatever } uad.ProfileThumbPicURL = string.Empty; uad.ProfilePicURL = string.Empty; uad.Update(); } else if (str == "2" || str == "3") { ups = new UserPhotos(); ups.GetUserPhotos(uad.UserAccountID); foreach (UserPhoto up1 in ups) { try { if ((up1.RankOrder == 1 && str == "2") || (up1.RankOrder == 2 && str == "3")) { if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.PicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.PicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL); } up1.Delete(); } } catch { // whatever } } // update ranking ups = new UserPhotos(); ups.GetUserPhotos(uad.UserAccountID); if (ups.Count == 1 && ups[0].RankOrder == 2) { ups[0].RankOrder = 1; ups[0].Update(); } } Response.Redirect("~/account/editphoto"); return new EmptyResult(); }
private void LoadCurrentImagesViewBag(int userAccountID) { var ups = new UserPhotos(); ups.GetUserPhotos(userAccountID); switch (ups.Count) { case 0: { var up = new UserPhoto(); ups.Add(up); up = new UserPhoto(); ups.Add(up); } break; case 1: { var up = new UserPhoto {RankOrder = 2}; ups.Add(up); } break; } if (!string.IsNullOrWhiteSpace(ups[0].PicURL)) { ViewBag.SecondUserPhotoFull = ups[0].FullProfilePicURL; ViewBag.SecondUserPhotoThumb = ups[0].FullProfilePicThumbURL; } if (string.IsNullOrWhiteSpace(ups[1].PicURL)) return; ViewBag.ThirdUserPhotoFull = ups[1].FullProfilePicURL; ViewBag.ThirdUserPhotoThumb = ups[1].FullProfilePicThumbURL; }
public ActionResult EditPhotoDelete() { string str = Request.Form["delete_photo"]; _uad = new UserAccountDetail(); if (_mu != null) _uad.GetUserAccountDeailForUser(Convert.ToInt32(_mu.ProviderUserKey)); var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; switch (str) { case "1": try { if (!string.IsNullOrWhiteSpace(_uad.RawProfilePicUrl) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.RawProfilePicUrl)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.RawProfilePicUrl); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.ProfilePicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.ProfilePicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, _uad.ProfileThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, _uad.ProfileThumbPicURL); } } catch { // whatever } // set to blank the profile images that were deleted _uad.RawProfilePicUrl = string.Empty; _uad.ProfileThumbPicURL = string.Empty; _uad.ProfilePicURL = string.Empty; _uad.Update(); break; case "3": case "2": _ups = new UserPhotos(); _ups.GetUserPhotos(_uad.UserAccountID); foreach (UserPhoto up1 in _ups) { try { if ((up1.RankOrder != 1 || str != "2") && (up1.RankOrder != 2 || str != "3")) continue; if (!string.IsNullOrWhiteSpace(up1.RawPicUrl) && s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.RawPicUrl)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.RawPicUrl); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.PicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.PicURL); } if (s3.ObjectExists(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL)) { s3.DeleteObject(AmazonCloudConfigs.AmazonBucketName, up1.ThumbPicURL); } up1.Delete(); } catch { // whatever } } _ups = new UserPhotos(); _ups.GetUserPhotos(_uad.UserAccountID); if (_ups.Count == 1 && _ups[0].RankOrder == 2) { _ups[0].RankOrder = 1; _ups[0].Update(); } break; } return RedirectToAction("EditPhoto"); }
public ActionResult EditPhoto(HttpPostedFileBase file) { UserPhoto up1 = null; var currentUserId = Convert.ToInt32(_mu.ProviderUserKey); int swapID; const CannedAcl acl = CannedAcl.PublicRead; var s3 = new S3Service { AccessKeyID = AmazonCloudConfigs.AmazonAccessKey, SecretAccessKey = AmazonCloudConfigs.AmazonSecretKey }; if (Request.Form["new_default"] != null && int.TryParse(Request.Form["new_default"], out swapID)) { // swap the default with the new default up1 = SwapOutDefaultPhoto(currentUserId, swapID); return View(_uad); } const string photoOne = "photo_edit_1"; const string photoTwo = "photo_edit_2"; const string photoThree = "photo_edit_3"; if (_mu != null) LoadCurrentImagesViewBag(currentUserId); _uad = new UserAccountDetail(); if (_mu != null) _uad.GetUserAccountDeailForUser(currentUserId); if (file == null) { ViewBag.IsValid = false; ModelState.AddModelError(string.Empty, Messages.NoFile); return View(_uad); } string photoEdited = Request.Form["photo_edit"]; string rawPhotoToDelete = string.Empty; string mainPhotoToDelete = string.Empty; string thumbPhotoToDelete = string.Empty; _ups = new UserPhotos(); _ups.GetUserPhotos(_uad.UserAccountID); if (string.IsNullOrEmpty(_uad.ProfilePicURL) || _ups.Count == 2 && photoEdited == photoOne) { rawPhotoToDelete = _uad.RawProfilePicUrl; mainPhotoToDelete = _uad.ProfilePicURL; thumbPhotoToDelete = _uad.ProfileThumbPicURL; } else { if (_ups.Count > 1 && photoEdited == photoTwo) { up1 = new UserPhoto(_ups[0].UserPhotoID) { RankOrder = 1 }; rawPhotoToDelete = up1.RawPicUrl; mainPhotoToDelete = up1.PicURL; thumbPhotoToDelete = up1.ThumbPicURL; } else if (_ups.Count > 1 && photoEdited == photoThree) { up1 = new UserPhoto(_ups[1].UserPhotoID) { RankOrder = 2 }; rawPhotoToDelete = up1.RawPicUrl; mainPhotoToDelete = up1.FullProfilePicURL; thumbPhotoToDelete = up1.ThumbPicURL; } } if (!string.IsNullOrEmpty(mainPhotoToDelete)) { DeletePhotos(s3, rawPhotoToDelete, mainPhotoToDelete, thumbPhotoToDelete); } var photoBitmap = new Bitmap(file.InputStream); // 300x 300 and raw up1 = ProcessMainPhotoItem(file, up1, currentUserId, acl, s3, photoOne, photoTwo, photoThree, photoEdited, photoBitmap); // 75 x 75 (thumbnail) var thumbFileName = AddPhotoToBucket(file, acl, s3, photoBitmap, true, 75, 75); if (string.IsNullOrEmpty(_uad.ProfileThumbPicURL) || _ups.Count == 2 && photoEdited == photoOne) { _uad.ProfileThumbPicURL = thumbFileName; _uad.LastPhotoUpdate = DateTime.UtcNow; _uad.Set(); } else { if (up1 != null) { if (_mu != null) up1.UserAccountID = currentUserId; up1.ThumbPicURL = thumbFileName; if ( (_ups.Count == 0 && photoEdited == photoTwo) || (_ups.Count > 0 && photoEdited == photoTwo) ) { up1.RankOrder = 1; } else if ( (_ups.Count == 0 && photoEdited == photoThree) || (_ups.Count > 1 && photoEdited == photoThree) ) { up1.RankOrder = 2; } } } photoBitmap.Dispose(); if (up1 != null && up1.UserPhotoID == 0) { if (_mu != null) up1.CreatedByUserID = currentUserId; up1.Create(); } else if (up1 != null && up1.UserPhotoID > 0) { up1.UpdatedByUserID = currentUserId; up1.Update(); } LoadCurrentImagesViewBag(currentUserId); return View(_uad); }
private void LoadCurrentImagesViewBag(int userAccountID) { var ups = new UserPhotos(); ups.GetUserPhotos(userAccountID); switch (ups.Count) { case 0: { var up = new UserPhoto(); ups.Add(up); up = new UserPhoto(); ups.Add(up); } break; case 1: { var up = new UserPhoto {RankOrder = 2}; ups.Add(up); } break; } ViewBag.SecondUserPhotoFull = ups[0].FullProfilePicURL; ViewBag.SecondUserPhotoThumb = ups[0].FullProfilePicThumbURL; ViewBag.SecondUserPhotoID = ups[0].UserPhotoID; ViewBag.ThirdUserPhotoFull = ups[1].FullProfilePicURL; ViewBag.ThirdUserPhotoThumb = ups[1].FullProfilePicThumbURL; ViewBag.ThirdUserPhotoID = ups[1].UserPhotoID; }
public ActionResult Index() { InterestIdentityViewBags(); FindUsersModel model = new FindUsersModel(); LoadFilteredUsers(false, model); ViewBag.FilteredUsers = uas.ToUnorderdList; // random Role rle = new Role(SiteEnums.RoleTypes.cyber_girl.ToString()); UserAccounts girlModels = UserAccountRole.GetUsersInRole(rle.RoleID); if (girlModels!= null && girlModels.Count > 0) { BootBaronLib.Operational.StaticHelper.Shuffle(girlModels); UserAccount featuredModel = girlModels[0]; UserAccountDetail featuredPhoto = new UserAccountDetail(); featuredPhoto.GetUserAccountDeailForUser(featuredModel.UserAccountID); int photoNumber = Utilities.RandomNumber(1, 4); string photoPath = featuredPhoto.FullProfilePicURL; if (photoNumber > 1) { UserPhotos ups = new UserPhotos(); ups.GetUserPhotos(featuredModel.UserAccountID); if (ups.Count > 0) { foreach (UserPhoto up1 in ups) { if ((up1.RankOrder + 1) == photoNumber) { photoPath = up1.FullProfilePicURL; break; } } } } // random border color with random user pic from their 3 photos string[] colorBorder = BootBaronLib.Configs.GeneralConfigs.RandomColors.Split(','); Random rnd=new Random(); string[] myRandomArray = colorBorder.OrderBy(x => rnd.Next()).ToArray(); ViewBag.FeaturedModel = string.Format(@" <a class=""m_over"" href=""{1}""> <img src=""{0}"" class=""featured_user"" style="" border: 2px dashed {2}; "" /></a>", photoPath, featuredModel.UrlTo.ToString(), myRandomArray[0]); } return View(model); }
private void LoadCurrentImagesViewBag(int userAccountID) { UserPhotos ups = new UserPhotos(); ups.GetUserPhotos(userAccountID); if (ups.Count == 0) { UserPhoto up = new UserPhoto(); ups.Add(up); up = new UserPhoto(); ups.Add(up); } else if (ups.Count == 1) { UserPhoto up = new UserPhoto(); up.RankOrder = 2; ups.Add(up); } if (!string.IsNullOrWhiteSpace(ups[0].PicURL)) { ViewBag.SecondUserPhotoFull = ups[0].FullProfilePicURL; ViewBag.SecondUserPhotoThumb = ups[0].FullProfilePicThumbURL; } if (!string.IsNullOrWhiteSpace(ups[1].PicURL)) { ViewBag.ThirdUserPhotoFull = ups[1].FullProfilePicURL; ViewBag.ThirdUserPhotoThumb = ups[1].FullProfilePicThumbURL; } }