コード例 #1
0
        public async Task <IActionResult> Create(BikeFormModel bykeModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(bykeModel));
            }

            var userId = this.userManager.GetUserId(User);

            await this.bikes.CreateAsync(bykeModel.Make, bykeModel.Model, bykeModel.Price, bykeModel.ImageUrl, bykeModel.Quantity, bykeModel.FrameSize, bykeModel.WheelesMake, bykeModel.ForkMake, bykeModel.TiresMake, bykeModel.ShiftersMake, bykeModel.FrontDerailleur, bykeModel.RearDerailleur, bykeModel.Chain, bykeModel.Saddle, bykeModel.Handlebar, bykeModel.Brakes, bykeModel.Color, bykeModel.BrakeLevers, bykeModel.BatteryMake, bykeModel.BatteryPower, bykeModel.BarTape, bykeModel.RearShockMake, bykeModel.Kickstand, userId);

            TempData.AddSuccessMessage($"Bike {bykeModel.Make} {bykeModel.Model} created successfully!");

            return(RedirectToAction(nameof(Index)));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, BikeFormModel bikeModel)
        {
            var updatedBike = await this.bikes.EditAsync(
                id,
                bikeModel.Make,
                bikeModel.Model,
                bikeModel.Price,
                bikeModel.ImageUrl,
                bikeModel.Quantity,
                bikeModel.FrameSize,
                bikeModel.WheelesMake,
                bikeModel.ForkMake,
                bikeModel.TiresMake,
                bikeModel.ShiftersMake,
                bikeModel.FrontDerailleur,
                bikeModel.RearDerailleur,
                bikeModel.Chain,
                bikeModel.Saddle,
                bikeModel.Handlebar,
                bikeModel.Brakes,
                bikeModel.Color,
                bikeModel.BrakeLevers,
                bikeModel.BatteryMake,
                bikeModel.BatteryPower,
                bikeModel.BarTape,
                bikeModel.RearShockMake,
                bikeModel.Kickstand,
                this.userManager.GetUserId(User));

            if (!updatedBike)
            {
                return(NotFound());
            }

            return(RedirectToAction(nameof(Index)));
        }