public async Task <IActionResult> Edit(int id, [Bind("License_Plate,Km_Price,Day_Price,Type")] EmployeeVehicleModel employeeVehicleModel)
        {
            if (id != employeeVehicleModel.License_Plate)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employeeVehicleModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeVehicleModelExists(employeeVehicleModel.License_Plate))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeVehicleModel));
        }
        public async Task <IActionResult> Create([Bind("License_Plate,Km_Price,Day_Price,Type")] EmployeeVehicleModel employeeVehicleModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employeeVehicleModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeVehicleModel));
        }
Ejemplo n.º 3
0
        public IActionResult Index(int currentPage, Occupation occupation, long vehicleId)
        {
            ViewBag.OcccupationSelected = occupation;

            var membersWorking = _memberRest.FindAll(new MemberFilter {
                EmployeeStatus = EmployeeStatus.Working
            }).Model;

            var membersGuidWorking = membersWorking
                                     .Select(d => d.EmployeeGuid).Distinct()
                                     .ToList();

            var employees = _employeeRest.FindPaginated(new EmployeeFilter
            {
                Occupation          = occupation,
                EmployeeGuidWorking = membersGuidWorking,
                IsMember            = true,
                CurrentPage         = currentPage == 0 ? 1 : currentPage
            });

            var vehicles = _vehicleRest.FindAll(new VehicleFilter());

            var currentVehicle = vehicles.Model.FirstOrDefault();

            if (vehicleId > 0)
            {
                currentVehicle = vehicles.Model.FirstOrDefault(d => d.Id == vehicleId);
            }

            ViewBag.VehicleId = currentVehicle.Id;

            List <EmployeeVehicleModel> employeeVehicles = new List <EmployeeVehicleModel>();

            foreach (var memberWorking in membersWorking.Where(d => d.VehicleId == currentVehicle.Id))
            {
                var employee = _employeeRest.Find(new EmployeeFilter {
                    Guid = memberWorking.EmployeeGuid
                }).Model;
                if (employee != null)
                {
                    EmployeeVehicleModel employeeVehicleModel = new EmployeeVehicleModel
                    {
                        EmployeeModel = employee,
                        VehicleModel  = currentVehicle,
                        MemberId      = memberWorking.Id
                    };
                    employeeVehicles.Add(employeeVehicleModel);
                }
            }

            return(View(new MemberRegisterModel {
                EmployeeModels = employees, VehicleModels = vehicles.Model, EmployeeVehicleModels = employeeVehicles
            }));
        }