Beispiel #1
0
 public IActionResult CreateAdvertisementItem([FromBody] NewAdvertisementItem newAdvertisementModel)
 {
     try
     {
         var userId = this.identityService.GetUserId(User.Identity);
         this.advertisementItemService.CreateNewAdvertisementItem(newAdvertisementModel, userId);
         return(Json("Ok"));
     }
     catch (Exception exc)
     {
         Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         logger.LogError("Wystąpił wyjątek w trakcie tworzenia nowego ogłoszenia: " + exc);
         return(Json(new ErrorResponse {
             ErrorMessage = exc.Message
         }));
     }
 }
Beispiel #2
0
        private NewAdvertisementItem CreateNewAdvertisementItemModel(AdvertisementItemPhotosNames photosListModel)
        {
            var location = this.gpsLocationService.GetLocation();
            NewAdvertisementItem model = new NewAdvertisementItem();

            model.Id = editModel != null ? editModel.Id : -1;
            model.AdvertisementTitle       = advertisementTitle.Text;
            model.AdvertisementDescription = advertisementDescription.Text;
            model.Size               = this.size;
            model.Latitude           = location.Latitude;
            model.Longitude          = location.Longitude;
            model.IsOnlyForSell      = rdBtnOnlyForSell.Checked;
            model.AdvertisementPrice = Int32.Parse(advertisementPrice.Text);
            model.Category           = this.categoryInfoModel;
            model.PhotosNames        = photosListModel.PhotosNames;

            return(model);
        }
Beispiel #3
0
        public async Task <bool> CreateNewAdvertisement(NewAdvertisementItem newAdvertisementModel)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(newAdvertisementModel), Encoding.UTF8, "application/json");
            HttpResponseMessage response;

            try
            {
                response = await client.PostAsync(WebApiConsts.ADVERTISEMENT_CONTROLLER + "CreateAdvertisementItem", stringContent);
            }
            catch
            {
                response = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
            }
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(false);
            }
            return(true);
        }
        public void CreateNewAdvertisementItem(NewAdvertisementItem newAdvertisementModel, string userId)
        {
            AdvertisementItem model = null;

            if (newAdvertisementModel.Id > 0)
            {
                model                = this.advertisementItemDbService.GetByIdWithPhotos(newAdvertisementModel.Id);
                model.Title          = newAdvertisementModel.AdvertisementTitle;
                model.Description    = newAdvertisementModel.AdvertisementDescription;
                model.Size           = newAdvertisementModel.Size;
                model.Price          = newAdvertisementModel.AdvertisementPrice;
                model.ExpirationDate = GetExpirationDate();
                model.Latitude       = newAdvertisementModel.Latitude;
                model.Longitude      = newAdvertisementModel.Longitude;
                model.IsOnlyForSell  = newAdvertisementModel.IsOnlyForSell;
                model.CategoryId     = newAdvertisementModel.Category.Id;
                model.AdvertisementPhotos.AddRange(CreateAdvertisementPhotosModels(newAdvertisementModel.PhotosNames));
            }
            else
            {
                model = new AdvertisementItem
                {
                    UserId              = userId,
                    Title               = newAdvertisementModel.AdvertisementTitle,
                    Description         = newAdvertisementModel.AdvertisementDescription,
                    Size                = newAdvertisementModel.Size,
                    Price               = newAdvertisementModel.AdvertisementPrice,
                    CreationDate        = DateTime.Now,
                    ExpirationDate      = GetExpirationDate(),
                    Latitude            = newAdvertisementModel.Latitude,
                    Longitude           = newAdvertisementModel.Longitude,
                    IsOnlyForSell       = newAdvertisementModel.IsOnlyForSell,
                    CategoryId          = newAdvertisementModel.Category.Id,
                    AdvertisementPhotos = CreateAdvertisementPhotosModels(newAdvertisementModel.PhotosNames)
                };
            }

            this.advertisementItemDbService.SaveNewAdvertisementItem(model);
        }