コード例 #1
0
ファイル: ConverterHelper.cs プロジェクト: danny1510/Biker
 public async Task <MotorBikeSpareEntity> ToMotorbikeSpareEntityasync(
     AddMotorBikeSpareViewModel model,
     string path,
     bool Isnew)
 {
     return(new MotorBikeSpareEntity
     {
         YearSince = model.YearSince,
         YearUntil = model.YearUntil,
         ImageUrl = path,
         MotorBike = await _dataContext.MotorBikes.FindAsync(model.MotorbikeId),
         Id = Isnew ? 0 : model.Id
     });
 }
コード例 #2
0
        public async Task <IActionResult> EditBikeS(AddMotorBikeSpareViewModel model)
        {
            if (ModelState.IsValid)
            {
                var path = model.ImageUrl;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile, "MotorBikesSpare");
                }

                var motorbikeSpare = await _converterHelper.ToMotorbikeSpareEntityasync(model, path, false);

                _context.MotorBikeSpares.Update(motorbikeSpare);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"Details/{model.MotorbikeId}"));
            }
            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> AddBikeS(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var motorBike = await _context.MotorBikes.FindAsync(id.Value);

            if (motorBike == null)
            {
                return(NotFound());
            }

            var model = new AddMotorBikeSpareViewModel
            {
                MotorbikeId = motorBike.Id,
                YearSince   = 2020,
                YearUntil   = 2020,
                Id          = 0
            };

            return(View(model));
        }