Exemplo n.º 1
0
        public virtual ActionResult Info(VendorInfoModel model, HttpPostedFileBase uploadedFile)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(new HttpUnauthorizedResult());
            }

            if (_workContext.CurrentVendor == null || !_vendorSettings.AllowVendorsToEditInfo)
            {
                return(RedirectToRoute("CustomerInfo"));
            }

            Picture picture = null;

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    var contentType         = uploadedFile.ContentType;
                    var vendorPictureBinary = uploadedFile.GetPictureBits();
                    picture = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Account.VendorInfo.Picture.ErrorMessage"));
                }
            }

            var vendor      = _workContext.CurrentVendor;
            var prevPicture = _pictureService.GetPictureById(vendor.PictureId);

            if (ModelState.IsValid)
            {
                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);

                vendor.Name        = model.Name;
                vendor.Email       = model.Email;
                vendor.Description = description;

                if (picture != null)
                {
                    vendor.PictureId = picture.Id;

                    if (prevPicture != null)
                    {
                        _pictureService.DeletePicture(prevPicture);
                    }
                }

                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                _vendorService.UpdateVendor(vendor);

                //notifications
                if (_vendorSettings.NotifyStoreOwnerAboutVendorInformationChange)
                {
                    _workflowMessageService.SendVendorInformationChangeNotification(vendor, _localizationSettings.DefaultAdminLanguageId);
                }

                return(RedirectToAction("Info"));
            }

            //If we got this far, something failed, redisplay form
            model = _vendorModelFactory.PrepareVendorInfoModel(model, true);
            return(View(model));
        }
        public JsonResult UploadAlbumPicture(int albumId, HttpPostedFileBase pictureFile)
        {
            var album = _customerAlbumPictureService.GetCustomerAlbumById(albumId);


            if (album.Pictures.Count >= _mobSocialSettings.MaximumMainAlbumPictures)
            {
                throw new ApplicationException("You may only upload up to " + _mobSocialSettings.MaximumMainAlbumPictures + " pictures at this time.");
            }

            // Verify that the user selected a file
            if (pictureFile != null && pictureFile.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(pictureFile.FileName);


                string albumFolder = string.Format("~/Content/Images/Albums/{0}/{1}",
                                                   album.CustomerId, albumId);

                var albumPicturePath = Path.Combine(_webHelper.MapPath(albumFolder), fileName);
                albumPicturePath = FileUtility.FilePathAddNumberIfExists(albumPicturePath, _webHelper.MapPath(albumFolder));

                var directoryPath = Path.GetDirectoryName(albumPicturePath);
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                pictureFile.SaveAs(albumPicturePath);

                var thumbnailFileName = Path.GetFileNameWithoutExtension(albumPicturePath) + "-thumbnail" + Path.GetExtension(albumPicturePath);
                var thumbnailPath     = Path.Combine(_webHelper.MapPath(albumFolder), thumbnailFileName);
                var thumbnailWidth    = _mobSocialSettings.CustomerAlbumPictureThumbnailWidth;
                var resizedPicture    = _customerAlbumPictureService.CreateThumbnailPicture(pictureFile.GetPictureBits(), thumbnailWidth, pictureFile.ContentType);

                System.IO.File.WriteAllBytes(thumbnailPath, resizedPicture);

                var albumPicture = new CustomerAlbumPicture()
                {
                    Album           = album,
                    CustomerAlbumId = albumId,
                    DateCreated     = DateTime.Now,
                    DisplayOrder    = 0,
                    ThumbnailUrl    = thumbnailPath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty),
                    Url             = albumPicturePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty)
                };

                _customerAlbumPictureService.Insert(albumPicture);

                return(Json(albumPicture));
            }


            return(Json(null));
        }
Exemplo n.º 3
0
        public virtual ActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, HttpPostedFileBase uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(new HttpUnauthorizedResult());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            int pictureId = 0;

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    var contentType         = uploadedFile.ContentType;
                    var vendorPictureBinary = uploadedFile.GetPictureBits();
                    var picture             = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);

                    if (picture != null)
                    {
                        pictureId = picture.Id;
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
                }
            }

            if (ModelState.IsValid)
            {
                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
                //disabled by default
                var vendor = new Vendor
                {
                    Name  = model.Name,
                    Email = model.Email,
                    //some default settings
                    PageSize = 6,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions,
                    PictureId       = pictureId,
                    Description     = description,
                    DisplayAddress  = model.DisplayAddress,
                    Active          = true
                };
                _vendorService.InsertVendor(vendor);
                //search engine name (the same as vendor name)
                var seName = vendor.ValidateSeName(vendor.Name, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, seName, 0);

                //associate to the current customer
                //but a store owner will have to manually add this customer role to "Vendors" role
                //if he wants to grant access to admin area
                _workContext.CurrentCustomer.VendorId = vendor.Id;
                var allCustomerRoles = _customerService.GetAllCustomerRoles(true);
                foreach (var customerRole in allCustomerRoles)
                {
                    if (customerRole.Name == "Vendors")
                    {
                        _workContext.CurrentCustomer.CustomerRoles.Add(customerRole);
                        break;
                    }
                }
                _customerService.UpdateCustomer(_workContext.CurrentCustomer);

                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                //notify store owner here (email)
                _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                        vendor, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model = _vendorModelFactory.PrepareApplyVendorModel(model, false, true);
            return(View(model));
        }
Exemplo n.º 4
0
        public ActionResult InsertPicture(string authToken, HttpPostedFileBase httpPostedFile)
        {
            //Workaround for flash cookie bug
            //http://stackoverflow.com/questions/1729179/uploadify-session-and-authentication-with-asp-net-mvc
            //http://geekswithblogs.net/apopovsky/archive/2009/05/06/working-around-flash-cookie-bug-in-asp.net-mvc.aspx

            var ticket = FormsAuthentication.Decrypt(authToken);

            if (ticket == null)
            {
                throw new Exception("No token provided");
            }

            var identity = new FormsIdentity(ticket);

            if (!identity.IsAuthenticated)
            {
                throw new Exception("User is not authenticated");
            }

            var customer = ((FormsAuthenticationService)_authenticationService).GetAuthenticatedCustomerFromTicket(ticket);

            if (!customer.IsAdmin())
            {
                throw new Exception("User is not admin");
            }

            byte[] pictureBinary = httpPostedFile.GetPictureBits();



            //TODO: find a better solution: little hack here
            //'Uploadify' component uploads all files with "application/octet-stream" mime type
            //that's why we manually update it here
            //http://www.sfsu.edu/training/mimetype.htm
            string contentType   = httpPostedFile.ContentType;
            string fileExtension = Path.GetExtension(httpPostedFile.FileName);

            if (!String.IsNullOrEmpty(fileExtension))
            {
                fileExtension = fileExtension.ToLowerInvariant();
            }
            switch (fileExtension)
            {
            case ".bmp":
                contentType = "image/bmp";
                break;

            case ".gif":
                contentType = "image/gif";
                break;

            case ".jpeg":
            case ".jpg":
            case ".jpe":
            case ".jfif":
            case ".pjpeg":
            case ".pjp":
                contentType = "image/jpeg";
                break;

            case ".png":
                contentType = "image/png";
                break;

            case ".tiff":
            case ".tif":
                contentType = "image/tiff";
                break;

            default:
                break;
            }

            var picture = _pictureService.InsertPicture(pictureBinary, contentType, null, true);

            return(Json(new { pictureId = picture.Id, imageUrl = _pictureService.GetPictureUrl(picture, 100) }));
        }