public int AddVehicle(NewVehicleVm vehVm)
        {
            var veh = _mapper.Map <Vehicle>(vehVm);
            var id  = _vehicleRepo.AddVehicle(veh);

            return(id);
        }
Exemple #2
0
 public ActionResult Edit(Guid?id)
 {
     try
     {
         var vehicle = Db.Vehicles.Include(x => x.VehicleType).FirstOrDefault(x => x.Id == id);
         var model   = new NewVehicleVm()
         {
             Id            = vehicle.Id,
             Code          = vehicle.Code,
             Name          = vehicle.Name,
             Description   = vehicle.Description,
             Active        = vehicle.Active,
             VehicleTypeId = vehicle.VehicleType.Id.ToString(),
         };
         TempData["VehicleTypes"] = new SelectList(VehicleTypesList, "Value", "Text");
         return(PartialView("~/Views/Vehicles/Add.cshtml", model));
     }
     catch (Exception ex)
     {
         return(Json(new JsonResponse()
         {
             IsSucess = false, ErrorMessage = ex.Message
         }, JsonRequestBehavior.AllowGet));
     }
 }
        public IActionResult EditVehicle(int?id)
        {
            NewVehicleVm vehicle = _vehicleService.GetVehicleForEdit(id);

            vehicle.YearHelper        = vehicle.ProductionDate.Year;
            vehicle.VehicleFuelTypes  = _vehicleService.GetAllFuelsTypes().ToList();
            vehicle.VehicleBrandNames = _vehicleService.GetAllBrandNames().ToList();
            vehicle.VehicleTypes      = _vehicleService.GetVehicleTypes().ToList();
            return(View(vehicle));
        }
        public IActionResult AddNewVehicleForEmployee(NewVehicleVm vehVm)
        {
            if (!ModelState.IsValid)
            {
                vehVm.EngineTypes = _empService.GetEngineTypes().ToList();
                return(RedirectToAction("NewVehicle"));
            }
            var id = _empService.AddVehicle(vehVm);

            return(RedirectToAction("EditEmployee"));
        }
        /****Vehicle****/

        public IActionResult NewVehicle()
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var model  = new NewVehicleVm
            {
                EmployeeId  = _empService.GetEmployeeByUserId(userId).Id,
                EngineTypes = _empService.GetEngineTypes().ToList()
            };

            return(PartialView("AddNewVehicleForEmployee", model));
        }
        public void EditVehicle(NewVehicleVm vehicle)
        {
            vehicle.ProductionDate     = new DateTime(vehicle.YearHelper, 1, 1);
            vehicle.Vin                = vehicle.Vin.ToUpper();
            vehicle.RegistrationNumber = vehicle.RegistrationNumber.ToUpper();
            vehicle.Model              = vehicle.Model.ToUpper();

            var vehicleForUpdate = _mapper.Map <Vehicle>(vehicle);

            vehicleForUpdate.ModifiedDateTime = DateTime.UtcNow;
            _vehicleRepository.EditVehicle(vehicleForUpdate);
        }
        public IActionResult AddVehicle()
        {
            var userId = _userManager.GetUserId(User);


            var model = new NewVehicleVm()
            {
                VehicleFuelTypes  = _vehicleService.GetAllFuelsTypes().ToList(),
                VehicleBrandNames = _vehicleService.GetAllBrandNames().ToList(),
                VehicleTypes      = _vehicleService.GetVehicleTypes().ToList(),
                ApplicationUserID = userId
            };

            return(View(model));
        }
        public int AddVehicle(NewVehicleVm vehicle)
        {
            vehicle.Capacity           = vehicle.PermissibleGrossWeight - vehicle.OwnWeight;
            vehicle.ProductionDate     = new DateTime(vehicle.YearHelper, 1, 1);
            vehicle.Vin                = vehicle.Vin.ToUpper();
            vehicle.RegistrationNumber = vehicle.RegistrationNumber.ToUpper();
            vehicle.Model              = vehicle.Model.ToUpper();

            var vehicl = _mapper.Map <Domain.Model.Vehicle>(vehicle);

            vehicl.CreatedDateTime = DateTime.Now;
            vehicl.CreatedById     = "userid";
            vehicl.IsActive        = true;

            var result = _vehicleRepository.AddVehicle(vehicl);

            return(result); // result = 0 is false
        }
Exemple #9
0
        public ActionResult Save(NewVehicleVm vm)
        {
            try
            {
                if (vm.Id == null)
                {
                    Vehicle vehicle = new Vehicle()
                    {
                        Id            = Guid.NewGuid(),
                        Code          = vm.Code,
                        Name          = vm.Name,
                        VehicleTypeId = Guid.Parse(vm.VehicleTypeId),
                        Description   = vm.Description,
                        Active        = vm.Active,
                        CreatedAt     = DateTime.Now,
                        CreatedBy     = LoggedInUser?.UserName
                    };
                    Db.Vehicles.Add(vehicle);
                }
                else
                {
                    var vehcile = Db.Vehicles.FirstOrDefault(x => x.Id == vm.Id);
                    vehcile.Code          = vm.Code;
                    vehcile.Name          = vm.Name;
                    vehcile.VehicleTypeId = Guid.Parse(vm.VehicleTypeId);
                    vehcile.Description   = vm.Description;
                    vehcile.Active        = vm.Active;
                }
                Db.SaveChanges();

                return(Json(new JsonResponse()
                {
                    IsSucess = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new JsonResponse()
                {
                    IsSucess = false, ErrorMessage = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public IActionResult AddVehicle(NewVehicleVm models)
        {
            if (!ModelState.IsValid)
            {
                models.VehicleFuelTypes  = _vehicleService.GetAllFuelsTypes();
                models.VehicleBrandNames = _vehicleService.GetAllBrandNames().ToList();
                models.VehicleTypes      = _vehicleService.GetVehicleTypes().ToList();
                return(View(models));
            }
            var id = _vehicleService.AddVehicle(models);

            if (id != 0)
            {
                return(RedirectToAction("User", "UserVehicles"));
            }
            else
            {
                return(View(models));
            }
        }
        public IActionResult EditVehicle(NewVehicleVm vehicle)
        {
            if (vehicle is null)
            {
                throw new System.ArgumentNullException(nameof(vehicle));
                //add viewbag?
            }

            if (!ModelState.IsValid)
            {
                vehicle.YearHelper        = vehicle.ProductionDate.Year;
                vehicle.VehicleFuelTypes  = _vehicleService.GetAllFuelsTypes();
                vehicle.VehicleBrandNames = _vehicleService.GetAllBrandNames().ToList();
                vehicle.VehicleTypes      = _vehicleService.GetVehicleTypes().ToList();
                return(View(vehicle));
            }
            _vehicleService.EditVehicle(vehicle);

            return(RedirectToAction("UserVehicles", "User"));
        }
 public IActionResult EditVehicleForEmployee(NewVehicleVm vehVm)
 {
     _empService.UpdateVehicle(vehVm);
     return(RedirectToAction("EditEmployee"));
 }
        public void UpdateVehicle(NewVehicleVm vehVm)
        {
            var veh = _mapper.Map <Vehicle>(vehVm);

            _vehicleRepo.UpdateVehicle(veh);
        }