public virtual ActionResult Info() { if (!_workContext.CurrentCustomer.IsRegistered()) { return(new HttpUnauthorizedResult()); } if (_workContext.CurrentContributor == null || !_contributorSettings.AllowContributorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } var model = new ContributorInfoModel(); model = _contributorModelFactory.PrepareContributorInfoModel(model, false); return(View(model)); }
/// <summary> /// Prepare the contributor info model /// </summary> /// <param name="model">Contributor info model</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <returns>Contributor info model</returns> public virtual ContributorInfoModel PrepareContributorInfoModel(ContributorInfoModel model, bool excludeProperties) { if (model == null) { throw new ArgumentNullException("model"); } var contributor = _workContext.CurrentContributor; if (!excludeProperties) { model.Description = contributor.Description; model.Email = contributor.Email; model.Name = contributor.Name; } var picture = _pictureService.GetPictureById(contributor.PictureId); var pictureSize = _mediaSettings.AvatarPictureSize; model.PictureUrl = picture != null?_pictureService.GetPictureUrl(picture, pictureSize) : string.Empty; return(model); }
public virtual ActionResult Info(ContributorInfoModel model, HttpPostedFileBase uploadedFile) { if (!_workContext.CurrentCustomer.IsRegistered()) { return(new HttpUnauthorizedResult()); } if (_workContext.CurrentContributor == null || !_contributorSettings.AllowContributorsToEditInfo) { return(RedirectToRoute("CustomerInfo")); } Picture picture = null; if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName)) { try { var contentType = uploadedFile.ContentType; var contributorPictureBinary = uploadedFile.GetPictureBits(); picture = _pictureService.InsertPicture(contributorPictureBinary, contentType, null); } catch (Exception) { ModelState.AddModelError("", _localizationService.GetResource("Account.ContributorInfo.Picture.ErrorMessage")); } } var contributor = _workContext.CurrentContributor; var prevPicture = _pictureService.GetPictureById(contributor.PictureId); if (ModelState.IsValid) { var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false); contributor.Name = model.Name; contributor.Email = model.Email; contributor.Description = description; if (picture != null) { contributor.PictureId = picture.Id; if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } //update picture seo file name UpdatePictureSeoNames(contributor); _contributorService.UpdateContributor(contributor); //notifications if (_contributorSettings.NotifyStoreOwnerAboutContributorInformationChange) { _workflowMessageService.SendContributorInformationChangeNotification(contributor, _localizationSettings.DefaultAdminLanguageId); } return(RedirectToAction("Info")); } //If we got this far, something failed, redisplay form model = _contributorModelFactory.PrepareContributorInfoModel(model, true); return(View(model)); }