Пример #1
0
        public async Task <EditAdBindingModel> GetEditAdBindingModelById(int adId)
        {
            if (!await context.Ads.AnyAsync(x => x.Id == adId))
            {
                throw new ArgumentException(GlobalConstants.InvalidAdIdErrorMessage);
            }

            var adFromDb = await this.GetAdByIdAsync(adId);

            var currentUserId = this.usersService.GetCurrentUserId();

            if (adFromDb.SellerId != currentUserId)
            {
                throw new InvalidOperationException(NotOwnerOfAnAdErrorMessage);
            }

            var editAdDetailsViewModel = await GetEditAdViewModelByIdAsync(adId);

            var editAdAddressViewModel = await GetEditAdAddressViewModelByIdAsync(adId);

            var editAdViewModel = GetEditAdViewModel(editAdDetailsViewModel, editAdAddressViewModel);

            var editAdBindingModel = new EditAdBindingModel
            {
                EditAdViewModel = editAdViewModel
            };

            return(editAdBindingModel);
        }
Пример #2
0
        public async Task <IActionResult> Edit(EditAdBindingModel bindingModel)
        {
            await adService.EditAd(bindingModel.EditAdInputModel);

            TempData["SuccessfullyEditedAdsMessage"] = SuccessfullyEditedAdsMessage;

            return(RedirectToAction("ActiveAds"));
        }