public JsonNetResult SetAvatarFromFile(HttpPostedFileBase file)
        {
            // Validate that the file is valid
            var isValidImage = (file != null && file.ContentLength > 0 && AllowableImageFormats.Contains(file.ContentType.ToLower()));

            if (isValidImage)
            {
                // Save the image
                var bytes = GlobalUtilities.GetBytesFromStream(file.InputStream);
                Exigo.Images().SaveUncroppedCustomerAvatar(Identity.Current.CustomerID, bytes);
            }

            return(new JsonNetResult(new
            {
                success = isValidImage,
                length = file.ContentLength
            }));
        }
Esempio n. 2
0
        public JsonNetResult SetAvatarFromFile(HttpPostedFileBase file = null)
        {
            if (file == null)
            {
                return(new JsonNetResult(new
                {
                    success = false,
                    message = "Please choose a File to upload"
                }));
            }

            // Validate that the file is valid
            var isValidImage = (file != null && file.ContentLength > 0 && AllowableImageFormats.Contains(file.ContentType.ToLower()));

            if (isValidImage)
            {
                var maxWidth  = 500;
                var maxHeight = 500;

                // Save the image
                var bytes        = GlobalUtilities.GetBytesFromStream(file.InputStream);
                var resizedBytes = GlobalUtilities.ResizeImage(bytes, maxWidth, maxHeight);

                var html = this.RenderPartialViewToString("CropAvatar", resizedBytes);

                return(new JsonNetResult(new
                {
                    success = isValidImage,
                    html
                }));
            }

            return(new JsonNetResult(new
            {
                success = isValidImage
            }));
        }