Example #1
0
        public IActionResult PayTrafficTicket(int trafficTicketId)
        {
            try
            {
                TrafficTicket _trafficTicket = _trafficTicketService.Get(trafficTicketId);

                if (_trafficTicket != null)
                {
                    try
                    {
                        _trafficTicket.Pay();
                    }
                    catch (InvalidOperationException ex)
                    {
                        return(BadRequest(ex.Message));
                    }

                    return(Ok(_trafficTicketService.Update(_trafficTicket)));
                }
                else
                {
                    return(BadRequest("Multa não encontrada!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.InnerException));
            }
        }
        public List <TrafficTicket> GetMostCommonTrafficTickets()
        {
            Dictionary <int, int> listMostCommonAux = new Dictionary <int, int>();

            foreach (RegistryTrafficTicket registry in ListRegistryTrafficTickets)
            {
                int count;
                listMostCommonAux.TryGetValue(registry.Infraccion.Id, out count);
                count++;
                listMostCommonAux[registry.Infraccion.Id] = count;
            }

            listMostCommonAux = listMostCommonAux.ToList().OrderByDescending(item => item.Value).Take(5)
                                .ToDictionary(item => item.Key, item => item.Value);

            List <TrafficTicket> listMostCommon = new List <TrafficTicket>();

            foreach (KeyValuePair <int, int> registry in listMostCommonAux)
            {
                TrafficTicket trafficTicket = ListRegistryTrafficTickets.Find(item => item.Infraccion.Id == registry.Key).Infraccion;
                listMostCommon.Add(trafficTicket);
            }

            return(listMostCommon);
        }
Example #3
0
        public async Task <IActionResult> Pay(TrafficTicket trafficTicket)
        {
            await _movtechAPIService.PagarMulta(trafficTicket.Id);


            return(RedirectToAction("Index"));
        }
Example #4
0
        public bool AddRegistryTrafficTicket(TrafficTicket t, vehicle v, DateTime time)
        {
            RpRegistryTrafficTickets rpRegistry = new RpRegistryTrafficTickets();
            RpDrivers     rpD   = new RpDrivers();
            List <Driver> ListD = rpD.GetDrivers().ToList();
            Driver        d     = null;

            foreach (Driver driver in ListD)
            {
                foreach (vehicle car in driver.listVehicles)
                {
                    if (car.Registration == v.Registration)
                    {
                        d = driver;
                        break;
                    }
                }
            }

            if (d != null)
            {
                return(rpRegistry.AddRegistryTrafficTicket(t, v, d, time));
            }
            else
            {
                //TODO mandar mensaje error
                return(false);
            }
        }
        public bool AddTrafficTicket(int id, string description, int decreasePoint)
        {
            RpTrafficTickets rpTrafficTickets = new RpTrafficTickets();
            TrafficTicket    ticket           = new TrafficTicket(id, description, decreasePoint);

            return(rpTrafficTickets.AddTrafficTicket(ticket));
        }
Example #6
0
 public bool AddTrafficTicket(TrafficTicket newTrafficTicket)
 {
     try
     {
         ListTrafficTickets.Add(newTrafficTicket);
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
 public bool AddRegistryTrafficTicket(TrafficTicket t, vehicle v, Driver d, DateTime time)
 {
     try
     {
         RegistryTrafficTicket newRegistry = new RegistryTrafficTicket(this.GetNewIdRegistry(), t, v, d, time);
         ListRegistryTrafficTickets.Add(newRegistry);
         return(true);
     } catch (Exception ex)
     {
         return(false);
     }
 }
Example #8
0
        public async Task <IActionResult> GetTrafficTicket(int id)
        {
            TrafficTicket _traffickTricket = await _trafficTicketService.GetTrafficTicket(id);


            if (_traffickTricket != null)
            {
                return(Ok(_traffickTricket));
            }
            else
            {
                return(NotFound());
            }
        }
Example #9
0
        public IActionResult RegisterTrafficTicket([FromBody] RegisterTrafficTicketViewModel viewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Vehicle _vehicle = _vehicleService.GetByLicensePlate(viewModel.VehicleLicensePlate);
                    Driver  _driver  = _driverService.GetByCPF(viewModel.DriverCPF);

                    TrafficTicket _trafficTicket = new TrafficTicket()
                    {
                        Vehicle = _vehicle,
                        Driver  = _driver,

                        TrafficTicketDate = viewModel.TrafficTicketDate,
                        BilletExpiration  = viewModel.BilletExpiration,
                        Cost        = viewModel.Cost,
                        Level       = viewModel.Level,
                        Description = viewModel.Description,

                        CEP          = viewModel.CEP,
                        Street       = viewModel.Street,
                        Number       = viewModel.Number,
                        Neighborhood = viewModel.Neighborhood,
                        City         = viewModel.City,
                        UF           = viewModel.UF
                    };

                    string _trafficTicketFeedback = _trafficTicket.Validate();

                    if (_trafficTicketFeedback == "ok")
                    {
                        return(Created("", _trafficTicketService.Insert(_trafficTicket)));
                    }
                    else
                    {
                        return(BadRequest(_trafficTicketFeedback));
                    }
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.InnerException));
            }
        }
Example #10
0
 public async Task UpdateAsync(TrafficTicket item)
 {
     await _repository.UpdateAsync(item);
 }
Example #11
0
        public async Task <int> InsertAsync(TrafficTicket item)
        {
            await _repository.AddAsync(item);

            return(item.Id);
        }
Example #12
0
 public async Task DeleteAsync(TrafficTicket item)
 {
     await _repository.DeleteAsync(item);
 }
Example #13
0
        public async Task <IActionResult> Details(TrafficTicket trafficTicket)
        {
            TrafficTicket ticket = await _movtechAPIService.ConsultarMulta(trafficTicket.Id);

            return(View(ticket));
        }