public IActionResult GetCustomerAvatar(int id) { var customer = _workContext.CurrentCustomer; customer.Id = id; //var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer; //var customer try { //var customerAvatar = _pictureService.GetPictureById(_genericAttributeService.GetAttribute<int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute)); //var customerAvatarId = 0; //var test = _genericAttributeService.GetAttribute<int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute); //if (customerAvatar != null) // customerAvatarId = customerAvatar.Id; var model = new CustomerAvatarModel { AvatarUrl = _pictureService.GetPictureUrl( _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute), targetSize: _mediaSettings.AvatarPictureSize, showDefaultPicture: false ) }; return(Ok(model)); } catch (Exception e) { throw e; } }
public CommentModel(CommentListModel parent) { Guard.NotNull(parent, nameof(parent)); Avatar = new CustomerAvatarModel(); _parent = new WeakReference <CommentListModel>(parent); }
public virtual async Task <CustomerAvatarModel> PrepareAvatar(Customer customer) { var model = new CustomerAvatarModel(); model.AvatarUrl = await _pictureService.GetPictureUrl( await customer.GetAttribute <string>(_genericAttributeService, SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false); return(model); }
public virtual CustomerAvatarModel PrepareAvatar(Customer customer) { var model = new CustomerAvatarModel(); model.AvatarUrl = _pictureService.GetPictureUrl( customer.GetAttribute <string>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false); return(model); }
public virtual CustomerAvatarModel PrepareCustomerAvatarModel(CustomerAvatarModel model) { if (model == null) { throw new ArgumentNullException("model"); } model.AvatarUrl = _pictureService.GetPictureUrl( _workContext.CurrentCustomer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false); return(model); }
/// <summary> /// Prepare the customer avatar model /// </summary> /// <param name="model">Customer avatar model</param> /// <returns>Customer avatar model</returns> public virtual CustomerAvatarModel PrepareCustomerAvatarModel(CustomerAvatarModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } model.AvatarUrl = _pictureService.GetPictureUrl( _genericAttributeService.GetAttribute <int>(_workContext.CurrentCustomer, NopCustomerDefaults.AvatarPictureIdAttribute), _mediaSettings.AvatarPictureSize, false); return(model); }
/// <summary> /// Prepare the customer avatar model /// </summary> /// <param name="model">Customer avatar model</param> /// <returns>Customer avatar model</returns> public virtual CustomerAvatarModel PrepareCustomerAvatarModel(CustomerAvatarModel model) { //if (model == null) // throw new ArgumentNullException("model"); //model.AvatarUrl = _pictureService.GetPictureUrl( // _workContext.CurrentUser.GetAttribute<int>(SystemUserAttributeNames.AvatarPictureId), // _mediaSettings.AvatarPictureSize, // false); //return model; return(null); }
public ActionResult Avatar() { var customer = GetCurrentCustomer(); var mediaSetting = _settingService.GetMediaSettings(); var avatar = customer.GetCustomerAttributeValue <string>(CustomerAttributeNames.Avatar); var model = new CustomerAvatarModel { Id = customer.Id, AvatarUrl = avatar, MaxSize = mediaSetting.MaxAvatarSize, Exts = mediaSetting.AvatarFile }; return(View(model)); }
public IActionResult GetAvatar() { var customer = _workContext.CurrentCustomer; var model = new CustomerAvatarModel { }; var customerAvatar = _pictureService.GetPictureById(_genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute)); var customerAvatarId = 0; if (customerAvatar != null) { customerAvatarId = customerAvatar.Id; } _genericAttributeService.SaveAttribute(customer, NopCustomerDefaults.AvatarPictureIdAttribute, customerAvatarId); model.AvatarUrl = _pictureService.GetPictureUrl( _genericAttributeService.GetAttribute <int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute), _mediaSettings.AvatarPictureSize, false); var a = model.AvatarUrl; return(Ok(a)); }
/// <summary> /// Creates a customer avatar model. /// </summary> /// <param name="customer">Customer entity.</param> /// <param name="genericAttributeService">Generic attribute service.</param> /// <param name="pictureService">Picture service.</param> /// <param name="customerSettings">Customer settings.</param> /// <param name="mediaSettings">Media settings.</param> /// <param name="urlHelper">URL helper.</param> /// <param name="userName">User name.</param> /// <param name="large">Large size.</param> /// <returns>Customer avatar model.</returns> public static CustomerAvatarModel ToAvatarModel( this Customer customer, IGenericAttributeService genericAttributeService, IPictureService pictureService, CustomerSettings customerSettings, MediaSettings mediaSettings, UrlHelper urlHelper, string userName = null, bool large = false) { Guard.NotNull(customer, nameof(customer)); var model = new CustomerAvatarModel { Large = large, UserName = userName }; if (customer.IsGuest()) { model.AvatarLetter = 'G'; model.AvatarColor = "light"; } else { if (customer.FirstName.HasValue()) { model.AvatarLetter = customer.FirstName.First(); } else if (customer.LastName.HasValue()) { model.AvatarLetter = customer.LastName.First(); } else if (customer.FullName.HasValue()) { model.AvatarLetter = customer.FullName.First(); } else if (customer.Username.HasValue()) { model.AvatarLetter = customer.Username.First(); } else if (userName.HasValue()) { model.AvatarLetter = userName.First(); } else { model.AvatarLetter = '?'; } if (customerSettings.AllowViewingProfiles) { model.LinkUrl = urlHelper.RouteUrl("CustomerProfile", new { id = customer.Id }); } if (customerSettings.AllowCustomersToUploadAvatars) { var avatarId = customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId, genericAttributeService); model.PictureUrl = pictureService.GetUrl(avatarId, mediaSettings.AvatarPictureSize, FallbackPictureType.NoFallback); } if (model.PictureUrl.IsEmpty()) { model.AvatarColor = customer.GetAvatarColor(genericAttributeService); } } return(model); }
/// <summary> /// Creates a customer avatar model. /// </summary> /// <param name="customer">Customer entity.</param> /// <param name="genericAttributeService">Generic attribute service.</param> /// <param name="mediaService">Media service.</param> /// <param name="customerSettings">Customer settings.</param> /// <param name="mediaSettings">Media settings.</param> /// <param name="urlHelper">URL helper.</param> /// <param name="userName">User name.</param> /// <param name="large">Large size.</param> /// <returns>Customer avatar model.</returns> public static CustomerAvatarModel ToAvatarModel( this Customer customer, IGenericAttributeService genericAttributeService, CustomerSettings customerSettings, MediaSettings mediaSettings, string userName = null, bool large = false) { Guard.NotNull(customer, nameof(customer)); var model = new CustomerAvatarModel { Id = customer.Id, Large = large, UserName = userName, AvatarPictureSize = mediaSettings.AvatarPictureSize }; if (customer.IsGuest()) { model.AvatarLetter = 'G'; model.AvatarColor = "light"; } else { model.AllowViewingProfiles = customerSettings.AllowViewingProfiles; if (customer.FirstName.HasValue()) { model.AvatarLetter = customer.FirstName.First(); } else if (customer.LastName.HasValue()) { model.AvatarLetter = customer.LastName.First(); } else if (customer.FullName.HasValue()) { model.AvatarLetter = customer.FullName.First(); } else if (customer.Username.HasValue()) { model.AvatarLetter = customer.Username.First(); } else if (userName.HasValue()) { model.AvatarLetter = userName.First(); } else { model.AvatarLetter = '?'; } if (customerSettings.AllowCustomersToUploadAvatars) { model.FileId = customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId, genericAttributeService); } if (!model.FileId.HasValue) { model.AvatarColor = customer.GetAvatarColor(genericAttributeService); } } return(model); }