Exemplo n.º 1
0
 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
     });
 }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }