コード例 #1
0
 /// <summary>
 /// The save photo resize.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="resizeName">
 /// The resize name.
 /// </param>
 /// <returns>
 /// The JamesRocks.Photos.Models.Photo.
 /// </returns>
 public Photo SavePhotoResize(PhotoRequest item, string resizeName)
 {
     return Provider.SavePhotoResize(item, resizeName);
 }
コード例 #2
0
 /// <summary>
 /// The save photo for all sizes.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="keepOriginalSize">
 /// The keep original size.
 /// </param>
 /// <returns>
 /// The System.Collections.Generic.IList`1[T -&gt; JamesRocks.Photos.Models.Photo].
 /// </returns>
 public IList<Photo> SavePhotoForAllSizes(PhotoRequest item, bool keepOriginalSize)
 {
     return Provider.SavePhotoForAllSizes(item, keepOriginalSize);
 }
コード例 #3
0
 /// <summary>
 /// The save photo resize.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="resizeName">
 /// The resize name.
 /// </param>
 /// <returns>
 /// The JamesRocks.Photos.Models.Photo.
 /// </returns>
 public Photo SavePhotoResize(PhotoRequest item, string resizeName)
 {
     return(Provider.SavePhotoResize(item, resizeName));
 }
コード例 #4
0
 /// <summary>
 /// The save photo for all sizes.
 /// </summary>
 /// <param name="item">
 /// The item.
 /// </param>
 /// <param name="keepOriginalSize">
 /// The keep original size.
 /// </param>
 /// <returns>
 /// The System.Collections.Generic.IList`1[T -&gt; JamesRocks.Photos.Models.Photo].
 /// </returns>
 public IList <Photo> SavePhotoForAllSizes(PhotoRequest item, bool keepOriginalSize)
 {
     return(Provider.SavePhotoForAllSizes(item, keepOriginalSize));
 }
コード例 #5
0
        public ActionResult Photo(string button, HttpPostedFileBase file)
        {
            switch (button)
            {
                case "Remove":
                    {
                        #region REMOVE PHOTO

                        IDictionary<string, Photo> photoSizes =
                            PhotoManager.Provider.GetAllPhotoResizes(UserProfile.Current.PhotoId);

                        foreach (var photoSize in photoSizes)
                            System.IO.File.Delete(Server.MapPath(photoSize.Value.Url));

                        UserProfile.Current.PhotoId = null;
                        _userService.SetProfilePicture(UserProfile.Current.Tenant, UserProfile.Current.Username, null);

                        break;

                        #endregion
                    }
                case "Upload":
                    {
                        #region UPLOAD PHOTO

                        if (file != null)
                        {
                            // GET UPLOAD PHOTO REQUEST
                            var request = new PhotoRequest(file.InputStream, "image/png", null);

                            // UPLOAD PHOTO TO SERVER
                            var photoResult = PhotoManager.Provider.SavePhotoForAllSizes(request, true);

                            // VALIDATE PHOTO WAS UPLOADED TO SERVER
                            if (photoResult != null && photoResult.Count > 0)
                            {
                                var photo = PhotoManager.Provider.GetPhotoResize(photoResult[0].Id, "Medium");

                                // SAVE PHOTOID ON ACCOUNT
                                if (photo != null &&
                                    _userService.SetProfilePicture(UserProfile.Current.Tenant,
                                                                   UserProfile.Current.Username,
                                                                   photo.Id))
                                {
                                    // DELETE ALL SIZES OF OLD PHOTO
                                    if (!string.IsNullOrEmpty(UserProfile.Current.PhotoId))
                                    {
                                        IDictionary<string, Photo> photoSizes =
                                            PhotoManager.Provider.GetAllPhotoResizes(UserProfile.Current.PhotoId);

                                        foreach (var photoSize in photoSizes)
                                            System.IO.File.Delete(Server.MapPath(photoSize.Value.Url));
                                    }

                                    // ASSIGN NEW PHOTOID TO CURRENT USER AND RETURN VIEW
                                    UserProfile.Current.PhotoId = photo.Id;
                                    return View(photo);
                                }
                            }
                        }
                        else
                        {
                            // IF USER HAS A PHOTOID SET, DISPLAY IT
                            if (!string.IsNullOrWhiteSpace(UserProfile.Current.PhotoId))
                            {
                                var photo = PhotoManager.Provider.GetPhotoResize(UserProfile.Current.PhotoId, "Medium");
                                return View(photo);
                            }
                        }
                        break;

                        #endregion
                    }
            }

            return View(new Photo { Url = Url.Content("~/Content/images/Medium/Male.jpg") });
        }