public virtual IActionResult Create(VendorModel model, bool continueEditing, IFormCollection form) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors)) { return(AccessDeniedView()); } //parse vendor attributes var vendorAttributesXml = ParseVendorAttributes(form); _vendorAttributeParser.GetAttributeWarnings(vendorAttributesXml).ToList() .ForEach(warning => ModelState.AddModelError(string.Empty, warning)); if (ModelState.IsValid) { var vendor = model.ToEntity <Vendor>(); _vendorService.InsertVendor(vendor); //activity log _customerActivityService.InsertActivity("AddNewVendor", string.Format(_localizationService.GetResource("ActivityLog.AddNewVendor"), vendor.Id), vendor); //search engine name model.SeName = _urlRecordService.ValidateSeName(vendor, model.SeName, vendor.Name, true); _urlRecordService.SaveSlug(vendor, model.SeName, 0); //address var address = model.Address.ToEntity <Address>(); address.CreatedOnUtc = DateTime.UtcNow; //some validation if (address.CountryId == 0) { address.CountryId = null; } if (address.StateProvinceId == 0) { address.StateProvinceId = null; } _addressService.InsertAddress(address); vendor.AddressId = address.Id; _vendorService.UpdateVendor(vendor); //vendor attributes _genericAttributeService.SaveAttribute(vendor, NopVendorDefaults.VendorAttributes, vendorAttributesXml); //locales UpdateLocales(vendor, model); //update picture seo file name UpdatePictureSeoNames(vendor); _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added")); if (!continueEditing) { return(RedirectToAction("List")); } return(RedirectToAction("Edit", new { id = vendor.Id })); } //prepare model model = _vendorModelFactory.PrepareVendorModel(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public virtual IActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile) { if (!_vendorSettings.AllowCustomersToApplyForVendorAccount) { return(RedirectToRoute("HomePage")); } if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService)); } var pictureId = 0; if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName)) { try { var contentType = uploadedFile.ContentType; var vendorPictureBinary = _downloadService.GetDownloadBits(uploadedFile); var picture = _pictureService.InsertPicture(vendorPictureBinary, contentType, null); if (picture != null) { pictureId = picture.Id; } } catch (Exception) { ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage")); } } //vendor attributes var vendorAttributesXml = ParseVendorAttributes(model.Form); _vendorAttributeParser.GetAttributeWarnings(vendorAttributesXml).ToList() .ForEach(warning => ModelState.AddModelError(string.Empty, warning)); 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 = _urlRecordService.ValidateSeName(vendor, 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); //save vendor attributes _genericAttributeService.SaveAttribute(vendor, GSVendorDefaults.VendorAttributes, vendorAttributesXml); //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, vendorAttributesXml); return(View(model)); }