Exemplo n.º 1
0
        public async Task <IActionResult> Edit(EditCarBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.Redirect(string.Format(WebConstants.AdminCarsEdit, model.Id)));
            }
            var result = await this.carService.UpdateCarByIdAsync(
                model.Id,
                model.RegistrationPlate,
                model.Кilometers,
                model.YearOfManufacturing,
                model.EngineModel,
                model.EngineHorsePower,
                model.FuelTypeId,
                model.TransmissionId
                );

            if (result != default(int))
            {
                this.ShowNotification(string.Format(
                                          NotificationMessages.CarUpdatedSuccessfull),
                                      NotificationType.Success);
                return(this.Redirect(string.Format(WebConstants.EmployeesCarsDetails, model.Id)));
            }

            this.ShowNotification(string.Format(
                                      NotificationMessages.CarEditFail),
                                  NotificationType.Warning);
            return(this.View(model.Id));
        }
        public async Task <IActionResult> Edit(EditCarBindingModel model)
        {
            var userId = Content(this.User.GetUserId()).Content.ToString();

            model.UserId = userId;
            if (!ModelState.IsValid)
            {
                return(View());
            }
            await this.vehiclesService.EditAndSave(model);

            return(RedirectToAction("Details", new { id = model.Id }));
        }
Exemplo n.º 3
0
        public async Task <int> EditAndSave(EditCarBindingModel model)
        {
            var currentCar = await this.DbContext.Vehicles.FirstOrDefaultAsync(c => c.Id == model.Id);

            currentCar.Make                  = model.Make;
            currentCar.Modification          = model.Modification;
            currentCar.ImageUrl              = model.ImageUrl;
            currentCar.FirstRegistrationDate = model.FirstRegistrationDate;
            currentCar.HorsePower            = model.HorsePower;
            currentCar.Kilometers            = model.Kilometers;
            currentCar.Id     = model.Id;
            currentCar.UserId = model.UserId;

            await this.DbContext.SaveChangesAsync();

            return(currentCar.Id);
        }