Пример #1
0
        public async Task <int> CreateCar(string userId, AddCarInputModel input)
        {
            var newCar = new Car()
            {
                UserId     = userId,
                MakeId     = input.MakeId,
                Model      = input.Model,
                TopSpeed   = input.TopSpeed,
                Weight     = input.Weight,
                Horsepower = input.Horsepower,
                Year       = input.Year,
                Torque     = input.Torque,
            };

            if (input.MainImage != null)
            {
                var carMainImageUrl = await CloudinaryExtension.UploadFileAsync(this.cloudinary, input.MainImage);

                newCar.MainImageUrl = carMainImageUrl;
            }

            await this.carRepository.AddAsync(newCar);

            await this.carRepository.SaveChangesAsync();

            return(newCar.Id);
        }
Пример #2
0
        public async Task ChangeCoverPhoto(NewProfilePhotoInputModel input)
        {
            if (input.ProfilePhoto != null)
            {
                var user             = this.users.All().FirstOrDefault(u => u.Id == input.UserId);
                var newCoverPhotoUrl = await CloudinaryExtension.UploadFileAsync(this.cloudinary, input.ProfilePhoto);

                user.CoverPhotoUrl = newCoverPhotoUrl;
                await this.users.SaveChangesAsync();
            }
        }
Пример #3
0
        public async Task EditCar(CarDetailsEditViewModel input)
        {
            var carToEdit = this.carRepository
                            .All()
                            .FirstOrDefault(c => c.Id == input.Id);

            if (input.MainImage != null)
            {
                var carMainImageUrl = await CloudinaryExtension.UploadFileAsync(this.cloudinary, input.MainImage);

                carToEdit.MainImageUrl = carMainImageUrl;
            }

            carToEdit.Model      = input.Model;
            carToEdit.Year       = input.Year;
            carToEdit.Horsepower = input.Horsepower;
            carToEdit.Torque     = input.Torque;
            carToEdit.Weight     = input.Weight;
            carToEdit.TopSpeed   = input.TopSpeed;

            await this.carRepository.SaveChangesAsync();
        }