Beispiel #1
0
        private static int getProgressInPercent(End end, AdvertStatus status, int clicks, DateTime?startDate, DateTime?statusLastChangedDate, int totalSecsActive)
        {
            var totalActive = TimeSpan.FromSeconds(totalSecsActive) +
                              (status == AdvertStatus.Active ? DateTime.Now - statusLastChangedDate.Value : TimeSpan.Zero);

            return(getProgressInPercent(end, status, clicks, startDate, totalActive));
        }
Beispiel #2
0
        /// <summary>
        /// Utility method for sql queries
        /// </summary>
        public static int GetProgressInPercent(int endMode, int endValue, int advertStatus, int clicks, DateTime?startDate, DateTime?statusLastChangedDate, int totalSecsActive)
        {
            End          end    = End.FromModeValue((End.Mode)endMode, endValue);
            AdvertStatus status = (AdvertStatus)advertStatus;

            return(getProgressInPercent(end, status, clicks, startDate, statusLastChangedDate, totalSecsActive));
        }
        // List of adverts by status
        public IActionResult Adverts(int pag = 1, AdvertStatus status = AdvertStatus.Approved)
        {
            // Get application Id from current user
            var userId = HttpContext.User.Claims
                         .FirstOrDefault(c => c.Type == "UniAccomodationId")?.Value;
            // Get adverts from current landlord by status
            var advertListVM = new AdvertListViewModel();

            advertListVM.Adverts = advertRepository.Adverts
                                   .Where(adv =>
                                          adv.LandlordId == Int32.Parse(userId) &&
                                          adv.Status == status)
                                   .OrderByDescending(adv => adv.Id)
                                   .Skip((pag - 1) * pagingOptions.PageSize)
                                   .Take(pagingOptions.PageSize);
            // Pagination
            advertListVM.PagingInfo = new PagingInfo
            {
                CurrentPage  = pag,
                ItemsPerPage = pagingOptions.PageSize,
                TotalItems   = advertRepository.Adverts
                               .Where(adv => adv.LandlordId == Int32.Parse(userId) && adv.Status == status)
                               .Count()
            };
            advertListVM.Status = status;
            return(View(advertListVM));
        }
        public IActionResult Adverts(int pag = 1, AdvertStatus status = AdvertStatus.Approved)
        {
            // Get application Id from current user
            var userId = HttpContext.User.Claims
                         .FirstOrDefault(c => c.Type == "UniAccomodationId")?.Value;
            // Get approved adverts by the current officer
            // Rely on claims transformation to ensure userId is not null
            var advertListVM = new AdvertListViewModel();

            advertListVM.Adverts = advertRepository.Adverts
                                   .Where(adv => adv.OfficerId == int.Parse(userId) && adv.Status == status)
                                   .OrderByDescending(adv => adv.Id)
                                   .Skip((pag - 1) * pagingOptions.PageSize)
                                   .Take(pagingOptions.PageSize);
            // Pagination
            advertListVM.PagingInfo = new PagingInfo
            {
                CurrentPage  = pag,
                ItemsPerPage = pagingOptions.PageSize,
                TotalItems   = advertRepository.Adverts
                               .Where(adv => adv.OfficerId == int.Parse(userId) && adv.Status == status)
                               .Count()
            };
            advertListVM.Status = status;
            return(View("Adverts", advertListVM));
        }
Beispiel #5
0
    protected void LoginAdsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Status [4]
            AdvertStatus Status = (AdvertStatus)Convert.ToInt32(e.Row.Cells[4].Text);
            e.Row.Cells[4].Text = HtmlCreator.GetColoredStatus(Status);

            //Display Date[2]
            e.Row.Cells[2].Text = DateTime.Parse(e.Row.Cells[2].Text).ToShortDateString();

            //start [5] stop [6] remove[7]
            if (Status != AdvertStatus.Paused)
            {
                e.Row.Cells[5].Text = "&nbsp;";
            }

            if (Status != AdvertStatus.Active)
            {
                e.Row.Cells[6].Text = "&nbsp;";
            }

            if (Status != AdvertStatus.Rejected && Status != AdvertStatus.Stopped)
            {
                e.Row.Cells[7].Text = "&nbsp;";
            }
        }
    }
Beispiel #6
0
        private void changeStatus(DateTime now, AdvertStatus oldStatus, AdvertStatus newStatus)
        {
            // Null -> WaitingForAcceptance
            if (oldStatus == AdvertStatus.Null && newStatus == AdvertStatus.WaitingForAcceptance)
            {
                CreationDate = now;
            }

            // WaitingForAcceptance -> Active, WaitingForAcceptance -> Paused
            else if (oldStatus == AdvertStatus.WaitingForAcceptance && (newStatus == AdvertStatus.Active || newStatus == AdvertStatus.Paused))
            {
                StartDate = now;
            }

            // WaitingForAcceptance -> Rejected, Active -> Finished, Paused -> Finished
            else if ((oldStatus == AdvertStatus.WaitingForAcceptance && newStatus == AdvertStatus.Rejected) ||
                     (oldStatus == AdvertStatus.Active && newStatus == AdvertStatus.Finished) ||
                     (oldStatus == AdvertStatus.Paused && newStatus == AdvertStatus.Finished))
            {
                EndDate = now;
            }

            // Active -> Paused
            else if (oldStatus == AdvertStatus.Active && newStatus == AdvertStatus.Paused)
            {
                TotalSecsActive += (int)(now - StatusLastChangedDate.Value).TotalSeconds;
            }

            // Paused -> Active, Finshed -> Active, Finished -> Pause
            // nothing to do
        }
Beispiel #7
0
 public static bool CanBeRemoved(this AdvertStatus status)
 {
     if (status == AdvertStatus.Finished || status == AdvertStatus.Rejected)
     {
         return(true);
     }
     return(false);
 }
 public ResultHelper Post([FromBody] AdvertStatus advertStatus)
 {
     if (advertStatus == null)
     {
         return(new ResultHelper(true, advertStatus.AdvertStatusID, ResultHelper.UnSuccessMessage));
     }
     advertStatusService.Create(advertStatus);
     return(new ResultHelper(true, advertStatus.AdvertStatusID, ResultHelper.SuccessMessage));
 }
Beispiel #9
0
        public static ListItem[] GetListControlSource(AdvertStatus status)
        {
            var nextStatuses = status.GetNextStatuses();

            var query = from nextStatus in nextStatuses
                        orderby(int) nextStatus ascending
                        select GetSingleItemListControlSource(nextStatus);

            return(query.ToArray());
        }
Beispiel #10
0
        public void AddClick()
        {
            ClicksReceived++;

            if (ClicksReceived >= ClicksBought)
            {
                this.Status = AdvertStatus.Finished;
            }

            this.Save();
        }
        public ResultHelper Put(int id, [FromBody] AdvertStatus AdvertStatus)
        {
            if (AdvertStatus == null)
            {
                return(new ResultHelper(true, AdvertStatus.AdvertStatusID, ResultHelper.UnSuccessMessage));
            }


            advertStatusService.Set(AdvertStatus);
            return(new ResultHelper(true, AdvertStatus.AdvertStatusID, ResultHelper.SuccessMessage));
        }
Beispiel #12
0
 public bool Review(AdvertStatus status, string comments, int officerId)
 {
     if (Status == AdvertStatus.Pending)
     {
         Status    = status;
         Comments  = comments;
         OfficerId = officerId;
         return(true);
     }
     return(false);
 }
Beispiel #13
0
        public void Watched()
        {
            CompletionTimes++;

            if (CompletionTimes >= CompletionTimesBought)
            {
                this.Status = AdvertStatus.Finished;
            }

            this.Save();
        }
        public ResultHelper Delete(int id)
        {
            AdvertStatus advertStatus = advertStatusService.Get(id);

            if (advertStatus == null)
            {
                return(new ResultHelper(true, advertStatus.AdvertStatusID, ResultHelper.UnSuccessMessage));
            }

            advertStatusService.Delete(advertStatus);
            return(new ResultHelper(true, advertStatus.AdvertStatusID, ResultHelper.SuccessMessage));
        }
        private async Task ConfirmAdvertAsync(string id, string filePath, AdvertStatus status)
        {
            var confirmModel = new ConfirmAdvertRequestModel {
                Id = id, FilePath = filePath, Status = AdvertStatus.Active
            };
            var confirmApiCallResult = await _advertApiClient.Confirm(confirmModel).ConfigureAwait(false);

            if (!confirmApiCallResult)
            {
                throw new Exception(message: $"Cannot confirm advert of id={id}");
            }
        }
Beispiel #16
0
 private InTextAdvert(int userId, InTextAdvertPack pack, string title, string description, string url, PurchaseBalances targetBalance)
 {
     UserId         = userId;
     ClicksBought   = pack.Clicks;
     ClicksReceived = 0;
     PricePaid      = pack.Price;
     Title          = title;
     Description    = description;
     Url            = url;
     Status         = AdvertStatus.Active;
     TargetBalance  = targetBalance;
 }
Beispiel #17
0
    public static void ChangeAllStatuses(IEnumerable <int> externalBannersIds, AdvertStatus status)
    {
        foreach (var externalBannerId in externalBannersIds)
        {
            var externalBanner = new ExternalBannerAdvert(externalBannerId);

            if (status == AdvertStatus.Active)
            {
                externalBanner.Accept();
            }
            else if (status == AdvertStatus.Rejected)
            {
                externalBanner.Reject();
            }
        }
    }
Beispiel #18
0
    public static void ChangeAllStatuses(IEnumerable <int> ids, AdvertStatus status)
    {
        foreach (var id in ids)
        {
            var url = new UserUrl(id);

            if (status == AdvertStatus.Active)
            {
                url.Accept();
            }
            else if (status == AdvertStatus.Rejected)
            {
                url.Reject();
            }
        }
    }
Beispiel #19
0
 public AdvertUpdatedEvent(
     Guid id,
     CatchType catchType,
     double price,
     Advertiser advertiser,
     string pitch,
     FishingMethod fishingMethod,
     AdvertStatus status
     ) : base(id)
 {
     CatchType     = catchType;
     Price         = price;
     Advertiser    = advertiser;
     Pitch         = pitch;
     FishingMethod = fishingMethod;
     Status        = status;
 }
Beispiel #20
0
 private PTCOfferWall(int userId, PTCOfferWallPack pack, string title, string description,
                      bool pcAllowed, bool mobileAllowed, bool autosurfEnabled, int maxSingleUserDailyViews)
 {
     UserId                = userId;
     Status                = AdvertStatus.Active;
     CompletionTimes       = 0;
     CompletionTimesBought = pack.CompletionTimes;
     PricePaid             = pack.Price;
     DisplayTime           = pack.DisplayTime;
     Adverts               = pack.Adverts;
     Title                 = title;
     Description           = description;
     PCAllowed             = pcAllowed;
     MobileAllowed         = mobileAllowed;
     AutosurfEnabled       = autosurfEnabled;
     SingleUserViewsPerDay = maxSingleUserDailyViews;
 }
Beispiel #21
0
        private static int getProgressInPercent(End end, AdvertStatus status, int clicks, DateTime?startDate, TimeSpan totalActive)
        {
            if (status == AdvertStatus.Null ||
                status == AdvertStatus.WaitingForAcceptance)
            {
                return(0);
            }

            if (status == AdvertStatus.Finished ||
                status == AdvertStatus.Rejected || end.Value == 0)
            {
                return(100);
            }

            int returnValue = 0;

            switch (end.EndMode)
            {
            case End.Mode.Null:
            case End.Mode.Endless:
                return(0);

            case End.Mode.Clicks:
                returnValue = (int)(((double)clicks / end.Value) * 100);
                break;

            case End.Mode.Days:
                TimeSpan total = TimeSpan.FromDays(end.Value);
                returnValue = (int)(((double)totalActive.Ticks / total.Ticks) * 100);
                break;

            default:
                throw new NotImplementedException("Not implemented: " + end);
            }

            if (returnValue > 100)
            {
                return(100);
            }
            if (returnValue < 0)
            {
                return(0);
            }

            return(returnValue);
        }
Beispiel #22
0
    protected void AdPacksAdGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Shorten url [6]
            if (e.Row.Cells[6].Text.Length > 19)
            {
                e.Row.Cells[6].Text = e.Row.Cells[6].Text.Substring(0, 16) + "...";
            }

            //Status [5]
            AdvertStatus Status = (AdvertStatus)Convert.ToInt32(e.Row.Cells[5].Text);
            e.Row.Cells[5].Text = HtmlCreator.GetColoredStatus(Status);

            //Added as [4]
            PurchaseOption.Features AddedAsType = (PurchaseOption.Features)Convert.ToInt32(e.Row.Cells[4].Text);
            e.Row.Cells[4].Text = AddedAsType.ToString();
        }
    }
Beispiel #23
0
    protected void DirectRefsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            BannerAdvert BannerAd = new BannerAdvert(Convert.ToInt32(e.Row.Cells[1].Text));

            //Image [4]
            var Imag = new Image();
            Imag.ImageUrl       = e.Row.Cells[4].Text;
            Imag.Height         = Unit.Percentage(33);
            e.Row.Cells[4].Text = "";
            e.Row.Cells[4].Controls.Add(Imag);

            //Shorten url [3]
            if (e.Row.Cells[3].Text.Length > 39)
            {
                e.Row.Cells[3].Text = e.Row.Cells[3].Text.Substring(0, 36) + "...";
            }

            //End mode [14]
            End.Mode Mode = (End.Mode)Convert.ToInt32(e.Row.Cells[14].Text);

            //Status [15]
            AdvertStatus Status = (AdvertStatus)Convert.ToInt32(e.Row.Cells[15].Text);
            e.Row.Cells[15].Text = HtmlCreator.GetColoredStatus(Status);

            //Remove [18]
            if (!Status.CanBeRemoved())
            {
                e.Row.Cells[18].Text = "&nbsp;";
            }

            //Paused = APPROVED
            if (Status == AdvertStatus.Paused)
            {
                e.Row.Cells[15].Text = "<span style=\"color:#\">" + U4000.APPROVED + "</span>";
            }
        }
        else if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.Cells[12].Text = AppSettings.BannerAdverts.ImpressionsEnabled ? L1.IMPRESSIONS : L1.CLICKS;
        }
    }
Beispiel #24
0
        public static ISet <AdvertStatus> GetNextStatuses(this AdvertStatus currentStatus)
        {
            HashSet <AdvertStatus> modes = new HashSet <AdvertStatus>();

            switch (currentStatus)
            {
            case AdvertStatus.Null:
                modes.Add(AdvertStatus.WaitingForAcceptance);
                break;

            case AdvertStatus.WaitingForAcceptance:
                modes.Add(AdvertStatus.Active);
                modes.Add(AdvertStatus.Paused);
                modes.Add(AdvertStatus.Rejected);
                break;

            case AdvertStatus.Active:
                modes.Add(AdvertStatus.Paused);
                modes.Add(AdvertStatus.Finished);
                break;

            case AdvertStatus.Paused:
                modes.Add(AdvertStatus.Active);
                modes.Add(AdvertStatus.Finished);
                break;

            case AdvertStatus.Finished:
                modes.Add(AdvertStatus.Active);
                modes.Add(AdvertStatus.Paused);
                break;

            case AdvertStatus.Rejected:
                break;

            case AdvertStatus.Stopped:
                break;

            default: throw new NotImplementedException();
            }

            return(modes);
        }
Beispiel #25
0
 public void Pause()
 {
     Status = AdvertStatus.Paused;
     this.Save();
 }
Beispiel #26
0
 public override void Delete()
 {
     Status = AdvertStatus.Deleted;
     this.Save();
 }
Beispiel #27
0
 public static ListItem GetSingleItemListControlSource(AdvertStatus status)
 {
     return(new ListItem(status.ToString(), Convert.ToString((int)status)));
 }
Beispiel #28
0
 public static bool IsAfter(this AdvertStatus thisStatus, AdvertStatus otherStatus)
 {
     return(otherStatus.IsBefore(thisStatus));
 }
Beispiel #29
0
 public static bool IsBefore(this AdvertStatus thisStatus, AdvertStatus otherStatus)
 {
     return(true);
 }
Beispiel #30
0
        /// <exception cref="DbException" />
        public static List <TrafficExchangeAdvert> SelectAdvertsWith(AdvertStatus status)
        {
            var whereStatus = TableHelper.MakeDictionary(Advert.Columns.Status, (int)status);

            return(TableHelper.SelectRows <TrafficExchangeAdvert>(whereStatus));
        }