Ejemplo n.º 1
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var dbAd = _adsService.GetAdById(Ad.Id);
                if (dbAd == null)  // create new
                {
                    //get current user
                    var identityClaim = _httpContext.HttpContext.User;
                    var user          = _userService.GetUserAsync(identityClaim).Result;
                    Ad.Owner = user;
                    var success = _adsService.CreateAdAsync(Ad);
                    return(Redirect("MyAds"));
                    //todo: add success message
                }
                else // update
                {
                    _adsService.UpdateAdd(Ad);
                    //todo: add success message

                    return(Redirect("Index"));
                }
            }

            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(CreateAdInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(inputModel));
            }

            await adService.CreateAdAsync(inputModel);

            TempData["CreatedAd"] = SuccessfullyCreatedAdMessage;


            return(RedirectToAction("WaitingForApproval"));
        }