示例#1
0
        private async Task <HttpResponseMessage> InsertAd(CreateAdRequestViewModel CreateAdRequest)
        {
            var response = await HttpClient.PostAsJsonAsync <CreateAdRequestViewModel>("/api/Ads", CreateAdRequest);

            PublishHasError = !response.IsSuccessStatusCode;
            return(response);
        }
示例#2
0
        protected async Task CreatePayment(string methodPayment)
        {
            var CreateAdRequest = new CreateAdRequestViewModel
            {
                Ad    = Ad,
                Price = CurrentPrice
            };

            var response = await InsertAd(CreateAdRequest);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                Ad = JsonConvert.DeserializeObject <AdViewModel>(json);
                NavigationManager.NavigateTo($"/payment/{methodPayment}/{Ad.OrderNumber}");
            }
        }
示例#3
0
        private async Task ValidAd()
        {
            var CreateAdRequest = new CreateAdRequestViewModel
            {
                Ad    = Ad,
                Price = CurrentPrice
            };

            var response = await InsertAd(CreateAdRequest);

            if (!PublishHasError)
            {
                var json = await response.Content.ReadAsStringAsync();

                var Ad = JsonConvert.DeserializeObject <AdViewModel>(json);
                NavigationManager.NavigateTo(NavigationManager.ToAbsoluteUri($"/ads/ValidAd/{Ad.Id}").ToString(), true);
            }

            await InvokeAsync(StateHasChanged);
        }
        public async Task <ActionResult <AdModel> > Create(CreateAdRequestViewModel createAdRequestViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ad = (AdModel)createAdRequestViewModel.Ad;
            var applicationUser = (ViewApplicationUser)User;

            if (createAdRequestViewModel.Price != null)
            {
                ad.OrderNumber = string.Concat(DateTime.UtcNow.ToString("yyyMMddHHmmss"), rdm.Next(100000, 999999));

                Subscription     subscription = null;
                SubscriptionPack pack         = null;

                int delayToDisplay  = 0;
                int displayDuration = 0;

                if (applicationUser.IsAdmin || applicationUser.IsManager || applicationUser.IsUnlimited || applicationUser.IsUltimate)
                {
                    delayToDisplay  = 0;
                    ad.IsValid      = true;
                    ad.ValidateDate = DateTime.UtcNow;
                    displayDuration = 15;
                }
                else
                {
                    if (!applicationUser.HasSubscriptionValid)
                    {
                        delayToDisplay  = 2;
                        displayDuration = 2;
                    }
                    else
                    {
                        delayToDisplay  = 0;
                        displayDuration = 5;
                    }
                }

                var priceDisplayDuration = createAdRequestViewModel.Price.DisplayDuration.GetValueOrDefault(0);
                var priceDelayToDisplay  = createAdRequestViewModel.Price.DelayToDisplay;

                if (priceDelayToDisplay < delayToDisplay)
                {
                    delayToDisplay = priceDelayToDisplay;
                }

                if (priceDisplayDuration > displayDuration)
                {
                    displayDuration = priceDisplayDuration;
                }

                ad.StartDisplayTime = DateTime.UtcNow.AddDays(delayToDisplay);
                ad.EndDisplayTime   = ad.StartDisplayTime.AddDays(displayDuration);

                ad.AdPriceId = createAdRequestViewModel.Price.Id;
            }

            ad.OwnerId = applicationUser.Id;
            ad.Country = applicationUser.Country;

            await functionalUnitOfWork.AdRepository.Add(ad);

            var entity = await functionalUnitOfWork.AdRepository.FirstOrDefault(a => a.Id == ad.Id);

            await _adsUnitOfWork.CategoryAdRepository.Add(createAdRequestViewModel.Ad.ListIdCategory, ad.Id);

            await _eventTrackingService.Create(applicationUser.Id, "Ad", "create");

            return(Ok(entity));
        }