Exemplo n.º 1
0
        public ActionResult Add(CreateAdDto request)
        {
            try
            {
                request.UserId = GetUserId().Result;
                _createAdCommand.Execute(request);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Create(AdDTO ad)
        {
            if (!ModelState.IsValid)
            {
                return(View(ad));
            }

            try
            {
                _createAdCommand.Execute(ad);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(StatusCode(500, "An error has occured."));
            }
        }
Exemplo n.º 3
0
 public IActionResult Create([FromBody] AdViewModel viewModel)
 {
     try
     {
         _createAdCommand.Execute(new CreateAdDto()
         {
             Subject     = viewModel.Subject,
             UserId      = GetUserId().Result,
             Description = viewModel.Description,
             CategoryId  = viewModel.CategoryId,
         });
         return(StatusCode(201));
     }
     catch (EntityNotFoundException e)
     {
         return(UnprocessableEntity(e.Message));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }