public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } await _service.Add(Advertisement); return(RedirectToPage("/Index")); }
public async Task <CustomApiResponse> Post([FromBody] AdvertisementsDto entity) { var inputEntity = _mapper.Map <Advertisements>(entity); //if (await _advertisementService.IsExisted(entity.Name)) //{ // return new CustomApiResponse("AdvertisementName đã tồn tại", true); //} var result = await _advertisementService.Add(inputEntity); return(new CustomApiResponse(result)); }
public ActionResult <AdvertisementOutPut> PostAdvertisement(AdvertisementInput product) { if (product == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(_advertisementServices.Add(product)); }
public async Task <ActionResult <int> > Add([FromForm] AddAdvertisementRequest request) { try { var res = await _advService.Add(request); return(new OkObjectResult(res)); } catch (Exception exception) { _logger.LogError(exception.Message); throw exception; } }
public IActionResult SaveEntity(AdvertisementViewModel advertisementVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (advertisementVm.Id == 0) { _advertisementService.Add(advertisementVm); } else { _advertisementService.Update(advertisementVm); } _advertisementService.Save(); return(new OkObjectResult(advertisementVm)); }
public IActionResult Add(Advertisement advertisement, bool rentSale, bool balcony, IFormFile imageUrl) { if (_httpContextAccessor.HttpContext != null) { if (ModelState.IsValid) { var image = _utilities.UploadImages(_webHostEnvironment.WebRootPath, "images", imageUrl); var userId = _httpContextAccessor.HttpContext.Session.GetString("userId"); Advertisement addedAdvertisement = new Advertisement() { Title = advertisement.Title, Price = advertisement.Price, CityId = advertisement.CityId, SquareMeters = advertisement.SquareMeters, RoomId = advertisement.RoomId, Balcony = balcony, RentOrSale = rentSale, AddedByAgentId = userId, ImageUrl = image }; _advertisementService.Add(addedAdvertisement); return(RedirectToAction("List")); } } AdvertismenetViewModel advertismenetViewModel = new AdvertismenetViewModel() { SelectCity = _utilities.SelectCity(), SelectRoom = _utilities.SelectRoom() }; return(View(advertismenetViewModel)); }
public async Task Add([FromBody] CreateAdvertisementDto data) { await _advertisementService.Add(data); }
public int Add([Required] AdvertisementModel model) { return(service.Add(model).Result); }