public IActionResult Advert(Advert advert) { var userId = User.GetUserId(); advert.UserId = userId; if (!ModelState.IsValid) { var vm = new AdvertViewModel() { Advert = advert, Categories = _categoryService.GetCategories(), Heading = advert.Id == 0 ? "nowe ogłoszenie" : "edycja ogłoszenia" }; return(View("Advert", vm)); } if (advert.Id == 0) { _advertService.AddAdvert(advert); } else { _advertService.UpdateAdvert(advert, userId); } return(RedirectToAction("Adverts", "Advert")); }
public IActionResult AddAdvert([FromBody] AddAdvertModel model) { if (!ModelState.IsValid) { return(BadRequest()); } if (model.Name == null || model.TireSize == null || model.Condition == null || model.Color == null || model.Description == null) { return(BadRequest()); } var user = _userService.GetUserByID(Int32.Parse(HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value)); try { _advertService.AddAdvert(model, user); return(Json(new { success = "true" })); } catch (Exception) { return(Json(new { success = "false" })); } }
public async Task <IActionResult> AddAdvert(AddPaymentDto newAdvert) { ServiceResponse <GetPaymentDto> response = await _advertService.AddAdvert(newAdvert); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public ActionResult AddAdvert(AddAdvertViewModel advertToAdd) { if (!ModelState.IsValid) { advertToAdd.Categories = GetCategories(); return(View(advertToAdd)); } var userId = User.Identity.GetUserId(); var advertToAddDto = _mapper.Map <AddAdvertViewModel, AddAdvertDto>(advertToAdd); var addedAdvert = _advertService.AddAdvert(advertToAddDto, userId); if (addedAdvert == null) { return(View(advertToAdd)); } return(RedirectToAction("GetUserAdverts", "Advert")); }