protected void btnSubmit_Click(object sender, EventArgs e) { UserAccount ua = new UserAccount(); ua.GetUserAccountByEmail(txtEmail.Text.Trim()); if (ua.UserAccountID == 0) { litResult.Text = @"<span style=""color:red"">Email not found!</span>"; return; } UserAccountDetail uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(ua.UserAccountID); uad.EmailMessages = false; if (uad.Update()) { litResult.Text = @"<span style=""color:green"">Unsubscribed!</span>"; } else { litResult.Text = @"<span style=""color:red"">error!</span>"; } }
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); }
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(); }
public void Application_AuthenticateRequest(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(Request.QueryString[SiteEnums.QueryStringNames.language.ToString()]) && User != null) { MembershipUser mu = Membership.GetUser(); if (mu != null) { UserAccountDetail uad = new UserAccountDetail(); uad.GetUserAccountDeailForUser(Convert.ToInt32(mu.ProviderUserKey)); string language = Request.QueryString[SiteEnums.QueryStringNames.language.ToString()]; uad.DefaultLanguage = language; uad.Update(); } } }