コード例 #1
0
ファイル: AdsController.cs プロジェクト: 3nch3v/IDispatcher
        public async Task <IActionResult> Edit(AdvertisementInputModel input, int id)
        {
            if (!this.HasPermission(id))
            {
                return(this.Unauthorized());
            }

            if (!this.stringValidator.IsStringValid(input.Description, DescriptionMinLength))
            {
                this.ModelState.AddModelError("Error", EmptyBody);
            }

            if (!this.ModelState.IsValid)
            {
                var ad = this.adsService.GetById <EditAdvertisementViewModel>(id);

                ad.AdvertisementTypes = this.adsService.GetAllAdTypes <AdvertisementTypeViewModel>();

                return(this.View(ad));
            }

            await this.adsService.UpdateAsync <AdvertisementInputModel>(input, id);

            return(this.RedirectToAction(nameof(this.Ad), new { id }));
        }
コード例 #2
0
ファイル: AdsController.cs プロジェクト: 3nch3v/IDispatcher
        public IActionResult Create()
        {
            var input = new AdvertisementInputModel
            {
                AdvertisementTypes = this.adsService.GetAllAdTypes <AdvertisementTypeViewModel>(),
            };

            return(this.View(input));
        }
コード例 #3
0
ファイル: AdsController.cs プロジェクト: 3nch3v/IDispatcher
        public async Task <IActionResult> Create(AdvertisementInputModel input)
        {
            if (!this.stringValidator.IsStringValid(input.Description, DescriptionMinLength))
            {
                this.ModelState.AddModelError("Error", EmptyBody);
            }

            if (!this.ModelState.IsValid)
            {
                var invalidInput = new AdvertisementInputModel
                {
                    AdvertisementTypes = this.adsService.GetAllAdTypes <AdvertisementTypeViewModel>(),
                };

                return(this.View(invalidInput));
            }

            var userId = this.userManager.GetUserId(this.User);

            await this.adsService.CreateAsync <AdvertisementInputModel>(input, userId);

            return(this.RedirectToAction(nameof(this.All)));
        }