Пример #1
0
        public async Task AddCar()
        {
            CarAdd car = new CarAdd()
            {
                BodyStyle      = this.BodyStyle,
                DateProduction = this.DateProduction,
                EngineType     = this.EngineType,
                FuelType       = this.FuelType,
                Id             = this.Id,
                Model          = this.Model,
                OdoMeter       = this.OdoMeter
            };

            //
            try
            {
                await _car2EndPoint.PostCar(car);

                _addedViewModel.UpdateMessage("Komunikat", "Dodano rekord");
                _windowManager.ShowWindow(_addedViewModel);
            }
            catch
            {
                _addedViewModel.UpdateMessage("Ostrzeżenie", "Nie dodano rekord");
                _windowManager.ShowWindow(_addedViewModel);
            }
        }
Пример #2
0
 public async Task PostCar(CarAdd car)
 {
     using (HttpResponseMessage responseMessage = await _aPIHelper.ApiClient.PostAsJsonAsync("api/Cars/nowe2", car))
     {
         if (responseMessage.StatusCode == System.Net.HttpStatusCode.OK)
         {
             //ActivateItem(IoC.Get<Car2ViewModel>());
         }
         else
         {
             throw new Exception();
         }
     }
 }
Пример #3
0
        public CarAdd CreateCarAdd(CarAddInputModel model, string carId, string creatorId)
        {
            if (string.IsNullOrEmpty(carId))
            {
                throw new ArgumentException();
            }

            List <CarPicture> carPictures = new List <CarPicture>();

            foreach (var picture in model.Pictures)
            {
                if (!picture.FileName.EndsWith(PictureSuffix))
                {
                    throw new InvalidOperationException();
                }

                var pictureDirectory = Directory.GetCurrentDirectory() + Slash + Constants.RootDirectory + Slash + ImagesFolderName + Slash + CarImagesFolerName;

                var directory = Directory.CreateDirectory(pictureDirectory).ToString();

                var path = Path.Combine(directory, picture.FileName);

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    picture.CopyTo(stream);
                }

                var carPicture = new CarPicture
                {
                    Url = Slash + ImagesFolderName + Slash + CarImagesFolerName + Slash + picture.FileName
                };

                carPictures.Add(carPicture);
            }

            var carAdd = new CarAdd
            {
                Title          = model.Title,
                CarId          = carId,
                AdditionalInfo = model.AdditionalInfo,
                CreatorId      = creatorId,
                Pictures       = carPictures
            };

            this.db.CarAdds.Add(carAdd);
            this.db.SaveChanges();

            return(carAdd);
        }