public static SponsorDataModel ToModel(this SponsorData SponsorData, IPictureService _pictureService) { if (SponsorData == null) { return(new SponsorDataModel()); } var model = new SponsorDataModel() { Id = SponsorData.Id, BattleType = SponsorData.BattleType, BattleId = SponsorData.BattleId, SponsorCustomerId = SponsorData.SponsorCustomerId, PictureId = SponsorData.PictureId, DisplayName = SponsorData.DisplayName, TargetUrl = SponsorData.TargetUrl, DisplayOrder = SponsorData.DisplayOrder }; if (SponsorData.PictureId > 0) { model.PictureUrl = _pictureService.GetPictureUrl(model.PictureId); } return(model); }
public void Populate(BaseCardData data, UIEventListener.VoidDelegate onClickedDelegate = null, bool allowRecommending = false) { this.data = data; ShowSponsors(null != data as SponsorDataModel); if (activityParent.activeSelf) { titleLabel.text = data.title; global::System.DateTime date = data.ParseDateString(); companyLabel.text = data.company; timeDistanceLabel.text = date.ToString("t", global::System.Globalization.CultureInfo.CreateSpecificCulture("en-us")) + " | " + data.Proximity.ToString("#.##") + " miles"; nid = data.id; costLabel.text = (data.admission_adults <= 0) && (data.admission_children <= 0) ? "FREE" : " $ "; SetCategoryIcon(data.category); SetCardIcon(data.featured); if (null != data.image && !string.IsNullOrEmpty(data.image.serving_url)) { data.StartImageDownload(UpdatePrimaryImage, null); } // Grab a placeholder image during the download. primaryImage.mainTexture = PlaceholderImageManager.Instance.GetRandomImage((int)data.id); UIEventListener myListener = UIEventListener.Get(gameObject); myListener.onClick -= OnSponsorWebsitePressed; if (null != onClickedDelegate) { myListener.onClick -= onClickedDelegate; myListener.onClick += onClickedDelegate; } } else { SponsorDataModel sponsorData = data as SponsorDataModel; sponsorWebURL = sponsorData.website; if (null != sponsorData.image && !string.IsNullOrEmpty(sponsorData.image.serving_url)) { sponsorData.StartImageDownload(UpdatePrimaryImage, null); } // Grab a placeholder image during the download. sponsorImage.mainTexture = PlaceholderImageManager.Instance.GetRandomImage((int)data.id); UIEventListener myListener = UIEventListener.Get(gameObject); // Sponsors have a different onClick myListener.onClick -= onClickedDelegate; myListener.onClick -= OnSponsorWebsitePressed; myListener.onClick += OnSponsorWebsitePressed; } isPopulated = true; }
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 })); }