Пример #1
0
        public static SponsorPublicModel ToPublicModel(this Sponsor Sponsor, IWorkContext _workContext,
                                                       ICustomerService _customerService, IPictureService _pictureService, ISponsorService _sponsorService, IPriceFormatter _priceFormatter, MediaSettings _mediaSettings)
        {
            var customer = _customerService.GetCustomerById(Sponsor.CustomerId);

            if (customer == null)
            {
                return(null);
            }

            //get sponsor data
            var sponsorData = _sponsorService.GetSponsorData(Sponsor.BattleId, Sponsor.BattleType, Sponsor.CustomerId);

            var model = new SponsorPublicModel
            {
                SponsorshipStatus     = Sponsor.SponsorshipStatus,
                SponsorshipStatusName = Sponsor.SponsorshipStatus.ToString(),
                CustomerId            = Sponsor.CustomerId,
                SeName                 = customer.GetSeName(_workContext.WorkingLanguage.Id),
                SponsorName            = customer.GetFullName(),
                SponsorProfileImageUrl =
                    _pictureService.GetPictureUrl(
                        customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId),
                        _mediaSettings.AvatarPictureSize, false),
                SponsorshipAmount          = Sponsor.SponsorshipAmount,
                SponsorshipAmountFormatted =
                    _priceFormatter.FormatPrice(Sponsor.SponsorshipAmount, true, _workContext.WorkingCurrency),
                SponsorData     = sponsorData.ToModel(_pictureService),
                SponsorshipType = Sponsor.SponsorshipType
            };


            return(model);
        }
Пример #2
0
        public static SponsorPublicModel ToPublicModel(this Sponsor sponsor, IUserService userService, IMediaService pictureService, ISponsorService sponsorService, IFormatterService formatterService, MediaSettings mediaSettings)
        {
            var user = userService.Get(sponsor.UserId);
            if (user == null)
                return null;

            //get sponsor data
            var sponsorData = sponsorService.GetSponsorData(sponsor.BattleId, sponsor.BattleType, sponsor.UserId);

            var model = new SponsorPublicModel
            {
                SponsorshipStatus = sponsor.SponsorshipStatus,
                SponsorshipStatusName = sponsor.SponsorshipStatus.ToString(),
                CustomerId = sponsor.UserId,
                SeName = user.GetPermalink().ToString(),
                SponsorName = user.GetPropertyValueAs<string>(PropertyNames.DisplayName),
                SponsorProfileImageUrl =
                    pictureService.GetPictureUrl(user.GetPropertyValueAs<int>(PropertyNames.DefaultPictureId)),
                SponsorshipAmount = sponsor.SponsorshipAmount,
                SponsorshipAmountFormatted = formatterService.FormatCurrency(sponsor.SponsorshipAmount, ApplicationContext.Current.ActiveCurrency),
                SponsorData = sponsorData.ToModel(pictureService),
                SponsorshipType = sponsor.SponsorshipType
            };

            return model;
        }
Пример #3
0
        public static SponsorPublicModel ToPublicModel(this Sponsor sponsor, IUserService userService, IMediaService pictureService, ISponsorService sponsorService, IFormatterService formatterService, MediaSettings mediaSettings)
        {
            var user = userService.Get(sponsor.UserId);

            if (user == null)
            {
                return(null);
            }

            //get sponsor data
            var sponsorData = sponsorService.GetSponsorData(sponsor.BattleId, sponsor.BattleType, sponsor.UserId);

            var model = new SponsorPublicModel
            {
                SponsorshipStatus     = sponsor.SponsorshipStatus,
                SponsorshipStatusName = sponsor.SponsorshipStatus.ToString(),
                CustomerId            = sponsor.UserId,
                SeName                 = user.GetPermalink().ToString(),
                SponsorName            = user.GetPropertyValueAs <string>(PropertyNames.DisplayName),
                SponsorProfileImageUrl =
                    pictureService.GetPictureUrl(user.GetPropertyValueAs <int>(PropertyNames.DefaultPictureId)),
                SponsorshipAmount          = sponsor.SponsorshipAmount,
                SponsorshipAmountFormatted = formatterService.FormatCurrency(sponsor.SponsorshipAmount, ApplicationContext.Current.ActiveCurrency),
                SponsorData     = sponsorData.ToModel(pictureService),
                SponsorshipType = sponsor.SponsorshipType
            };


            return(model);
        }
        public IHttpActionResult SaveSponsorData(SponsorDataModel requestModel)
        {
            //here we update or reject the status of battle
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid Data" }));
            }

            //because a sponsor may have performed multiple transactions for a battle, we'd update all of them at once

            //first get the battle
            //TODO: Remove comment when picture battles are ready
            var battle = _videoBattleService.Get(requestModel.BattleId); // Model.BattleType == BattleType.Video ? _videoBattleService.GetById(Model.BattleId) : null;

            //first get battle
            var videoBattle = _videoBattleService.Get(requestModel.BattleId);
            var sponsors    = _sponsorService.GetSponsors(ApplicationContext.Current.CurrentUser.Id, requestModel.BattleId, BattleType.Video,
                                                          SponsorshipStatus.Accepted);

            //only the battle owner or the sponsor can save the sponsor data
            if (!(sponsors.Any() || videoBattle.ChallengerId == ApplicationContext.Current.CurrentUser.Id))
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            //get the sponsor data. Because battle owner can also save the data, we need to make sure that correct data is requested
            //because battle owner can save anybody's data while sponsor can save only his or her data
            var sponsorData = _sponsorService.GetSponsorData(requestModel.BattleId, requestModel.BattleType, sponsors.Any() ? ApplicationContext.Current.CurrentUser.Id : requestModel.SponsorCustomerId);

            sponsorData.DisplayName = requestModel.DisplayName;
            sponsorData.PictureId   = requestModel.PictureId;
            sponsorData.TargetUrl   = requestModel.TargetUrl;
            sponsorData.DateUpdated = DateTime.UtcNow;

            //display order can only be changed by battle owner depending on the amount or his choice
            if (videoBattle.ChallengerId == ApplicationContext.Current.CurrentUser.Id)
            {
                sponsorData.DisplayOrder = requestModel.DisplayOrder;
            }

            _sponsorService.SaveSponsorData(sponsorData);

            return(Json(new { Success = true }));
        }