public ActionResult ApplyVendorSubmit(ApplyVendorModel model) { if (!_vendorSettings.AllowCustomersToApplyForVendorAccount) return RedirectToRoute("HomePage"); if (!_workContext.CurrentCustomer.IsRegistered()) return new HttpUnauthorizedResult(); if (ModelState.IsValid) { //disabled by default var vendor = new Vendor { Name = model.Name, Email = model.Email, //some default settings PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions }; _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; _customerService.UpdateCustomer(_workContext.CurrentCustomer); //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 return View(model); }
public ActionResult ApplyVendor() { if (!_vendorSettings.AllowCustomersToApplyForVendorAccount) return RedirectToRoute("HomePage"); if (!_workContext.CurrentCustomer.IsRegistered()) return new HttpUnauthorizedResult(); var model = new ApplyVendorModel(); if (_workContext.CurrentCustomer.VendorId > 0) { //already applied for vendor account model.DisableFormInput = true; model.Result = _localizationService.GetResource("Vendors.ApplyAccount.AlreadyApplied"); return View(model); } model.Email = _workContext.CurrentCustomer.Email; return View(model); }
public 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 }; _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; _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.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage; return View(model); }