public virtual async Task <IActionResult> Info() { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } if (_workContext.CurrentVendor == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } var model = new VendorInfoModel(); var vendor = _workContext.CurrentVendor; model.Description = vendor.Description; model.Email = vendor.Email; model.Name = vendor.Name; model.PictureUrl = await _pictureService.GetPictureUrl(vendor.PictureId, _mediaSettings.AvatarPictureSize, false); var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id); model.Address = await _mediator.Send(new GetVendorAddress() { Language = _workContext.WorkingLanguage, Address = vendor.Address, ExcludeProperties = false, LoadCountries = () => countries, }); return(View(model)); }
/// <summary> /// Prepare the vendor info model /// </summary> /// <param name="model">Vendor info model</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <param name="overriddenVendorAttributesXml">Overridden vendor attributes in XML format; pass null to use VendorAttributes of vendor</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the vendor info model /// </returns> public virtual async Task <VendorInfoModel> PrepareVendorInfoModelAsync(VendorInfoModel model, bool excludeProperties, string overriddenVendorAttributesXml = "") { if (model == null) { throw new ArgumentNullException(nameof(model)); } var vendor = await _workContext.GetCurrentVendorAsync(); if (!excludeProperties) { model.Description = vendor.Description; model.Email = vendor.Email; model.Name = vendor.Name; } var picture = await _pictureService.GetPictureByIdAsync(vendor.PictureId); var pictureSize = _mediaSettings.AvatarPictureSize; (model.PictureUrl, _) = picture != null ? await _pictureService.GetPictureUrlAsync(picture, pictureSize) : (string.Empty, null); //vendor attributes if (string.IsNullOrEmpty(overriddenVendorAttributesXml)) { overriddenVendorAttributesXml = await _genericAttributeService.GetAttributeAsync <string>(vendor, NopVendorDefaults.VendorAttributes); } model.VendorAttributes = await PrepareVendorAttributesAsync(overriddenVendorAttributesXml); return(model); }
/// <summary> /// Prepare the vendor info model /// </summary> /// <param name="model">Vendor info model</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <param name="overriddenVendorAttributesXml">Overridden vendor attributes in XML format; pass null to use VendorAttributes of vendor</param> /// <returns>Vendor info model</returns> public virtual VendorInfoModel PrepareVendorInfoModel(VendorInfoModel model, bool excludeProperties, string overriddenVendorAttributesXml = "") { if (model == null) { throw new ArgumentNullException(nameof(model)); } var vendor = _workContext.CurrentVendor; if (!excludeProperties) { model.Description = vendor.Description; model.Email = vendor.Email; model.Name = vendor.Name; } var picture = _pictureService.GetPictureById(vendor.PictureId); var pictureSize = _mediaSettings.AvatarPictureSize; model.PictureUrl = picture != null?_pictureService.GetPictureUrl(picture, pictureSize) : string.Empty; //vendor attributes if (string.IsNullOrEmpty(overriddenVendorAttributesXml)) { overriddenVendorAttributesXml = _genericAttributeService.GetAttribute <string>(vendor, NopVendorDefaults.VendorAttributes); } model.VendorAttributes = PrepareVendorAttributes(overriddenVendorAttributesXml); return(model); }
public ActionResult Info() { if (!_workContext.CurrentCustomer.IsRegistered()) { return(new HttpUnauthorizedResult()); } if (_workContext.CurrentVendor == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } var vendor = _workContext.CurrentVendor; var picture = _pictureService.GetPictureById(vendor.PictureId); var pictureSize = _mediaSettings.AvatarPictureSize; var model = new VendorInfoModel { Description = vendor.Description, Email = vendor.Email, Name = vendor.Name, PictureUrl = picture != null?_pictureService.GetPictureUrl(picture, pictureSize) : string.Empty }; return(View(model)); }
public virtual async Task <IActionResult> Info() { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } if (_workContext.CurrentVendor == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } var model = new VendorInfoModel(); var vendor = _workContext.CurrentVendor; model.Description = vendor.Description; model.Email = vendor.Email; model.Name = vendor.Name; var picture = await _pictureService.GetPictureById(vendor.PictureId); var pictureSize = _mediaSettings.AvatarPictureSize; model.PictureUrl = picture != null ? await _pictureService.GetPictureUrl(picture, pictureSize) : string.Empty; var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id); await _addressViewModelService.PrepareVendorAddressModel(model : model.Address, address : vendor.Address, excludeProperties : false, loadCountries : () => countries, vendorSettings : _vendorSettings); return(View(model)); }
public virtual IActionResult Info() { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } if (_workContext.CurrentVendor == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } var model = new VendorInfoModel(); model = _vendorModelFactory.PrepareVendorInfoModel(model, false); return(View(model)); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> Info() { if (!await _customerService.IsRegisteredAsync(await _workContext.GetCurrentCustomerAsync())) { return(Challenge()); } if (await _workContext.GetCurrentVendorAsync() == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } var model = new VendorInfoModel(); model = await _vendorModelFactory.PrepareVendorInfoModelAsync(model, false); return(View(model)); }
/// <summary> /// Prepare the vendor info model /// </summary> /// <param name="model">Vendor info model</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <returns>Vendor info model</returns> public virtual VendorInfoModel PrepareVendorInfoModel(VendorInfoModel model, bool excludeProperties) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var vendor = _workContext.CurrentVendor; if (!excludeProperties) { model.Description = vendor.VendorDescription; model.Email = vendor.Email; model.Name = vendor.VendorName; } //var picture = _pictureService.GetPictureById(vendor.PictureId); //var pictureSize = _mediaSettings.AvatarPictureSize; //model.PictureUrl = picture != null ? _pictureService.GetPictureUrl(picture, pictureSize) : string.Empty; return(model); }
public virtual async Task <IActionResult> Info(VendorInfoModel model, IFormFile uploadedFile) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } if (_workContext.CurrentVendor == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } string pictureId = string.Empty; string contentType = string.Empty; byte[] vendorPictureBinary = null; if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName)) { try { contentType = uploadedFile.ContentType; if (string.IsNullOrEmpty(contentType)) { ModelState.AddModelError("", "Empty content type"); } else if (!contentType.StartsWith("image")) { ModelState.AddModelError("", "Only image content type is allowed"); } vendorPictureBinary = uploadedFile.GetPictureBits(); } catch (Exception) { ModelState.AddModelError("", _localizationService.GetResource("Account.VendorInfo.Picture.ErrorMessage")); } } var vendor = _workContext.CurrentVendor; var prevPicture = await _pictureService.GetPictureById(vendor.PictureId); if (ModelState.IsValid && ModelState.ErrorCount == 0) { 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 (vendorPictureBinary != null && !string.IsNullOrEmpty(contentType)) { var picture = await _pictureService.InsertPicture(vendorPictureBinary, contentType, null); if (picture != null) { vendor.PictureId = picture.Id; } } if (prevPicture != null) { await _pictureService.DeletePicture(prevPicture); } //update picture seo file name await UpdatePictureSeoNames(vendor); model.Address.ToEntity(vendor.Address, true); await _vendorService.UpdateVendor(vendor); //notifications if (_vendorSettings.NotifyStoreOwnerAboutVendorInformationChange) { await _workflowMessageService.SendVendorInformationChangeNotification(vendor, _storeContext.CurrentStore, _localizationSettings.DefaultAdminLanguageId); } return(RedirectToAction("Info")); } var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id); model.Address = await _mediator.Send(new GetVendorAddress() { Language = _workContext.WorkingLanguage, Model = model.Address, Address = vendor.Address, ExcludeProperties = false, LoadCountries = () => countries, }); return(View(model)); }
public virtual IActionResult Info(VendorInfoModel model, IFormFile uploadedFile) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } 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 = _downloadService.GetDownloadBits(uploadedFile); 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); //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); 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); //save vendor attributes _genericAttributeService.SaveAttribute(vendor, GSVendorDefaults.VendorAttributes, vendorAttributesXml); //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, vendorAttributesXml); return(View(model)); }
public 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 virtual IActionResult Info(VendorInfoModel model, IFormFile uploadedFile) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Challenge()); } 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 && ModelState.ErrorCount == 0) { 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); model.Address.ToEntity(vendor.Address, true); _vendorService.UpdateVendor(vendor); //notifications if (_vendorSettings.NotifyStoreOwnerAboutVendorInformationChange) { _workflowMessageService.SendVendorInformationChangeNotification(vendor, _localizationSettings.DefaultAdminLanguageId); } return(RedirectToAction("Info")); } _addressViewModelService.PrepareVendorAddressModel(model: model.Address, address: vendor.Address, excludeProperties: false, loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id), vendorSettings: _vendorSettings); return(View(model)); }
public virtual async Task <IActionResult> Info(VendorInfoModel model, IFormFile uploadedFile, IFormCollection form) { if (!await _customerService.IsRegisteredAsync(await _workContext.GetCurrentCustomerAsync())) { return(Challenge()); } var vendor = await _workContext.GetCurrentVendorAsync(); if (vendor == null || !_vendorSettings.AllowVendorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } Picture picture = null; if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName)) { try { var contentType = uploadedFile.ContentType.ToLowerInvariant(); if (!contentType.StartsWith("image/")) { ModelState.AddModelError("", await _localizationService.GetResourceAsync("Account.VendorInfo.Picture.ErrorMessage")); } else { var vendorPictureBinary = await _downloadService.GetDownloadBitsAsync(uploadedFile); picture = await _pictureService.InsertPictureAsync(vendorPictureBinary, contentType, null); } } catch (Exception) { ModelState.AddModelError("", await _localizationService.GetResourceAsync("Account.VendorInfo.Picture.ErrorMessage")); } } var prevPicture = await _pictureService.GetPictureByIdAsync(vendor.PictureId); //vendor attributes var vendorAttributesXml = await ParseVendorAttributesAsync(form); (await _vendorAttributeParser.GetAttributeWarningsAsync(vendorAttributesXml)).ToList() .ForEach(warning => ModelState.AddModelError(string.Empty, warning)); if (ModelState.IsValid) { var description = _htmlFormatter.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) { await _pictureService.DeletePictureAsync(prevPicture); } } //update picture seo file name await UpdatePictureSeoNamesAsync(vendor); await _vendorService.UpdateVendorAsync(vendor); //save vendor attributes await _genericAttributeService.SaveAttributeAsync(vendor, NopVendorDefaults.VendorAttributes, vendorAttributesXml); //notifications if (_vendorSettings.NotifyStoreOwnerAboutVendorInformationChange) { await _workflowMessageService.SendVendorInformationChangeNotificationAsync(vendor, _localizationSettings.DefaultAdminLanguageId); } return(RedirectToAction("Info")); } //If we got this far, something failed, redisplay form model = await _vendorModelFactory.PrepareVendorInfoModelAsync(model, true, vendorAttributesXml); return(View(model)); }