예제 #1
0
        public ActionResult UpdateProfilePhoto()
        {
            var user              = GetUser();
            var photo             = new UserPhotos();
            var databasePathSmall = "";
            var databasePathBig   = "";
            var flag              = false;
            var resizer           = new ImageResize();
            var tracer            = "";

            try
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        Image imgSmall      = resizer.RezizeImage(Image.FromStream(file.InputStream, true, true), 190, 190);
                        Image imgBig        = resizer.RezizeImage(Image.FromStream(file.InputStream, true, true), 640, 640);
                        var   fileName      = Path.GetFileName(file.FileName);
                        var   fileNameSmall = fileName.Replace(".", "-tumbnail.");
                        var   fileNameBig   = fileName.Replace(".", "-big.");
                        var   pathSmall     = Path.Combine(Server.MapPath("~/images/post-images"), fileNameSmall);
                        var   pathBig       = Path.Combine(Server.MapPath("~/images/post-images"), fileNameBig);
                        databasePathSmall = "../../images/post-images/" + fileNameSmall;
                        databasePathBig   = "../../images/post-images/" + fileNameBig;
                        tracer           += pathSmall + " " + pathBig;
                        imgSmall.Save(pathSmall);
                        imgBig.Save(pathBig);
                        flag = true;
                    }
                }
            }
            catch (Exception ex)
            {
                return(Json(new LoginResult(result: 0, error: ex.Message + " filename=" + tracer)));
            }
            user.UserProfilePhoto = databasePathSmall;
            _db.Users.Attach(user);
            photo.UserId         = user.Id;
            photo.UserPhotoSmall = databasePathSmall;
            photo.UserPhotoBig   = databasePathBig;
            _db.UserPhotos.Add(photo);
            _db.UsersLastMoves.Add(new UsersLastMoves {
                MoveDate = DateTime.Now, UserId = user.Id, UsersLastMoveText = " profil fotoğrafını güncelledi.", UsersMoveLink = "/users/album/" + user.Id
            });
            var entry = _db.Entry(user);

            entry.Property(e => e.UserProfilePhoto).IsModified = flag;
            try
            {
                _db.SaveChanges();
                return(Json(1));
            }
            catch (Exception)
            {
                return(Json(0));
            }
        }
예제 #2
0
        public bool Delete(UserPhotos item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var committed = 0;

            try
            {
                //if (session != null)
                //    _repositoryUserPhotos.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                // Domain Services?
                //_repositoryUserPhotos.Delete(Mapper.Map<Dominio.Entidades.UserPhotos>(item));
                _repositoryUserPhotos.Delete(item);
                committed = _unitOfWorkAsync.SaveChanges();
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            return(committed > 0);
        }
        private async Task SetupUser(User user)
        {
            ProfilePictureUrl = user.ProfilePictureUrl;
            UserGold          = user.GoldBalance;

            var photos = await photoService.GetPhotosForCurrentUser();

            NumberOfPhotos = photos.Items.Count;
            UserPhotos.ReplaceRange(photos.Items);
        }
예제 #4
0
        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);
        }
예제 #5
0
        public async Task LoadPhotosAsync(int skip, int limit)
        {
            string username = _isEditMode ? _profile.Username : _user.Username;

            var photosEnvelope = await _profileEndpoint.LoadPhotosAsync(username, skip, limit);

            var photos = _mapper.Map <List <PhotoDisplayModel> >(photosEnvelope.Photos);

            foreach (var photo in photos)
            {
                UserPhotos.Add(photo);
            }

            _pagination.ItemsCount = photosEnvelope.PhotosCount;
        }
예제 #6
0
        public bool Update(UserPhotos item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var committed = 0;

            try
            {
                //if (session != null)
                //    _repositoryUserPhotos.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                var validator = EntityValidatorFactory.CreateValidator();
                if (validator.IsValid(item))
                {
                    // Domain Services?
                    //_repositoryUserPhotos.Update(Mapper.Map<Dominio.Entidades.UserPhotos>(item));
                    _repositoryUserPhotos.Update(item);
                    committed = _unitOfWorkAsync.SaveChanges();
                }
                else
                {
                    throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(item));
                }
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            //_repositoryUserPhotos.Update(entity);
            return(committed > 0);
        }
예제 #7
0
        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();
        }
예제 #8
0
        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;
        }
예제 #9
0
        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");
        }
예제 #10
0
        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);
        }
예제 #11
0
        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;
        }
예제 #12
0
        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);
        }
예제 #13
0
 public UserPhotosCrudViewModel()
 {
     UserPhotos = new UserPhotos();
 }
예제 #14
0
 public void ApplyChanges(UserPhotos entity)
 {
     _repositoryUserPhotos.ApplyChanges(entity);
 }
예제 #15
0
        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;
        }
예제 #16
0
        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);
        }
예제 #17
0
        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;
            }
        }