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")); }
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.")); } }
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)); } }