コード例 #1
0
        public async Task <IActionResult> Create(CarCreateBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                var manufacturers = await this.GetAllManufacturers();

                model.Manufacturers = manufacturers;

                return(this.View(model));
            }

            var serviceModel = Mapper.Map <CarServiceModel>(model);

            serviceModel.Owner = new PoolItUserServiceModel
            {
                UserName = this.User.Identity.Name
            };

            var result = await this.carsService.CreateAsync(serviceModel);

            if (!result)
            {
                this.Error(NotificationMessages.CarCreateError);
            }

            this.Success(NotificationMessages.CarCreated);

            return(this.RedirectToAction("Create", "Rides", new { Area = "Rides" }));
        }
コード例 #2
0
ファイル: CarController.cs プロジェクト: VladAngelov/SoftUni
        public async Task <IActionResult> Create(CarCreateBindingModel carCreateBindingModel)
        {
            if (!this.ModelState.IsValid)
            {
                List <CarStatusServiceModel> allCarStatuses = await this.carService
                                                              .GetAllStatuses()
                                                              .ToListAsync();

                this.ViewData["statuses"] = allCarStatuses
                                            .Select(carStatus => new CarCreateCarStatusViewModel
                {
                    Name = carStatus.Name
                })
                                            .ToList();

                return(this.View());
            }

            string pictureUrl = await this.cloudinaryService.UploadPictureAsync(
                carCreateBindingModel.Picture,
                carCreateBindingModel.Model);

            CarServiceModel carServiceModel = AutoMapper.Mapper
                                              .Map <CarServiceModel>(carCreateBindingModel);

            carServiceModel.Picture = pictureUrl;

            await this.carService.Create(carServiceModel);

            return(this.Redirect("/"));
        }
コード例 #3
0
        public async Task <IActionResult> Create()
        {
            var manufacturers = await this.GetAllManufacturers();

            var model = new CarCreateBindingModel
            {
                Manufacturers = manufacturers
            };

            return(this.View(model));
        }