コード例 #1
0
        public ActionResult <List <AdvertismentResult> > GetAdvertismentByUserAndCategory(string userId, string categoryId,
                                                                                          string expression = null, DateTime?startDate = null, DateTime?endDate = null)
        {
            List <Advertisment> advertisments = _advertismentService
                                                .GetAdvertismentsByUserCategoryDateRange(userId, categoryId, expression, startDate, endDate)
                                                .ToList();

            return(AdvertHelper.TranslateToResponseObject(advertisments));
        }
コード例 #2
0
        /// <summary>
        /// Performs advertising (in a background worker).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void Advertising_DoWork(object sender, DoWorkEventArgs args)
        {
            var worker = (sender as BackgroundWorker);

            try
            {
                this.CurrentAdvert      = null;
                this.CurrentAdvertIndex = int.MaxValue;

                // Initialize advertising
                AdvertHelper.Init();

                // Shuffle adverts
                AdvertHelper.ShuffleAdverts();

                while (true)
                {
                    if (this.IsMainWindowClosing || AdvertHelper.AvailablesAdverts.Count == 0)
                    {
                        break;
                    }

                    // Get current advert index
                    if (this.CurrentAdvertIndex >= (AdvertHelper.AvailablesAdverts.Count - 1))
                    {
                        this.CurrentAdvertIndex = 0;
                    }
                    else
                    {
                        this.CurrentAdvertIndex += 1;
                    }

                    // Get current advert
                    this.CurrentAdvert = AdvertHelper.AvailablesAdverts[this.CurrentAdvertIndex];

                    // Report progress to show current advert
                    worker.ReportProgress(0);

                    // Sleep til new advert
                    Thread.Sleep(TimeSpan.FromSeconds(MainWindow.ADVERT_SECONDS));
                }
            }
            catch (Exception ex)
            {
                worker.ReportProgress(100, ex);
            }
        }
コード例 #3
0
        public ActionResult GetAdvertisments(AdvertismentSearchModel searchModel)
        {
            try
            {
                List <Advertisment> advertisments = new List <Advertisment>();

                ArgumentsValidator.Validate(nameof(searchModel), searchModel);
                // do not validate as this is optional
                //ArgumentsValidator.Validate(nameof(searchModel.UserId), searchModel.UserId);

                if (!searchModel.CategoryId.HasValue)
                {
                    advertisments = _advertismentService.GetAdvertisments(searchModel.Expression, searchModel.UserId)
                                    .ToList();
                }

                if (searchModel.CategoryId.HasValue)
                {
                    advertisments = _advertismentService
                                    .GetAdvertismentsByUserCategoryDateRange(searchModel.UserId,
                                                                             searchModel.CategoryId.Value.ToString(), searchModel.Expression, searchModel.StartDate,
                                                                             searchModel.EndDate)
                                    .ToList();
                }

                return(StatusCode(200, AdvertHelper.TranslateToResponseObject(advertisments)));
            }
            catch (ArgumentException ex)
            {
                Log.Error(ex, AdvertismentConstants.ARGUMENT_NULL);
                return(StatusCode(400));
            }
            catch (DbUpdateException)
            {
                return(new StatusCodeResult(507));
            }
            catch (Exception)
            {
                return(new StatusCodeResult(500));
            }
        }