public ActionResult UpdateAdvert(AdvertForCreationModel advert)
        {
            var authUser = this.HttpContext.Items["User"] as UserModel;

            _advertService.UpdateAdvert(advert, authUser.Id);

            return(NoContent());
        }
        public AdvertModel CreateAdvert(AdvertForCreationModel advert, int userId)
        {
            var mappedAdvert   = MapToAdvertEntity(advert, userId, "Live");
            var createdAdvert  = _repo.CreateAdvert(mappedAdvert);
            var advertToReturn = MapToModel(createdAdvert);

            return(advertToReturn);
        }
        public ActionResult <AdvertModel> CreateAdvert(AdvertForCreationModel advert)
        {
            // Get the authorised user
            var authUser = this.HttpContext.Items["User"] as UserModel;
            var userId   = authUser.Id;

            var createdAdvert = _advertService.CreateAdvert(advert, userId);

            return(CreatedAtRoute("GetAdvert", new { id = createdAdvert.Id }, createdAdvert));
        }
 public Advert MapToAdvertEntity(AdvertForCreationModel advert, int userId, string status)
 {
     return(new Advert
     {
         Headline = advert.Headline,
         Province = advert.Province,
         City = advert.City,
         AdvertDetails = advert.AdvertDetails,
         Price = advert.Price,
         Status = status,
         UserId = userId,
         Id = advert.Id
     });
 }
        public void UpdateAdvert(AdvertForCreationModel advert, int userId)
        {
            var mappedAdvert = MapToAdvertEntity(advert, userId, advert.Status);

            _repo.UpdateAdvert(mappedAdvert);
        }