Exemple #1
0
        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 }));
        }
Exemple #2
0
        public IActionResult Create()
        {
            var input = new AdvertisementInputModel
            {
                AdvertisementTypes = this.adsService.GetAllAdTypes <AdvertisementTypeViewModel>(),
            };

            return(this.View(input));
        }
Exemple #3
0
        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)));
        }