Beispiel #1
0
        public string Post([FromBody] Message obj)
        {
            SessionFactory          sessionsFactory = new SessionFactory();
            SessionsTable <Session> instance        = (SessionsTable <Session>)sessionsFactory.GetSessionInstance();
            var list  = Request.Headers.ToList();
            var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty);

            if (token == null)
            {
                return("NOT LOGED");
            }
            var dispatcher = instance.SelectDispatcherSession(token);
            var driver     = instance.SelectDriverSession(token);
            var manager    = instance.SelectManagerSession(token);

            if (dispatcher == null && driver == null && manager == null)
            {
                return("NOT EXISTING USER");
            }
            else if (obj == null)
            {
                return("NO OBJECT");
            }

            obj.dispatcher    = new Dopravio.Models.Dispatcher();
            obj.dispatcher.id = dispatcher.id;

            MessageFactory         messageFactory  = new MessageFactory();
            MessageTable <Message> instanceMessage = (MessageTable <Message>)messageFactory.GetMessageInstance();

            instanceMessage.Insert(obj);
            return("OK");
        }
Beispiel #2
0
        public string Delete(int id)
        {
            SessionFactory          sessionsFactory = new SessionFactory();
            SessionsTable <Session> instance        = (SessionsTable <Session>)sessionsFactory.GetSessionInstance();
            var list  = Request.Headers.ToList();
            var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty);

            if (token == null)
            {
                return("NOT LOGED");
            }
            var dispatcher = instance.SelectDispatcherSession(token);
            var driver     = instance.SelectDriverSession(token);
            var manager    = instance.SelectManagerSession(token);

            if (dispatcher == null && driver == null && manager == null)
            {
                return("NOT EXISTING USER");
            }


            MessageFactory         messageFactory  = new MessageFactory();
            MessageTable <Message> instanceMessage = (MessageTable <Message>)messageFactory.GetMessageInstance();

            instanceMessage.Delete(id);
            return("OK");
        }
Beispiel #3
0
        public string Post([FromBody] Vehicle obj)
        {
            SessionFactory          sessionsFactory = new SessionFactory();
            SessionsTable <Session> instance        = (SessionsTable <Session>)sessionsFactory.GetSessionInstance();
            var list  = Request.Headers.ToList();
            var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty);

            if (token == null)
            {
                return("NOT LOGED");
            }
            var dispatcher = instance.SelectDispatcherSession(token);
            var driver     = instance.SelectDriverSession(token);
            var manager    = instance.SelectManagerSession(token);

            if (dispatcher == null && driver == null && manager == null)
            {
                return("NOT EXISTING USER");
            }
            else if (obj == null)
            {
                return("NO OBJECT");
            }


            VehicleFactory vehicleFactory  = new VehicleFactory();
            var            instanceVehicle = vehicleFactory.GetVehicleInstance();

            instanceVehicle.Insert(obj);
            return("OK");
        }
Beispiel #4
0
        public string Put(int id, [FromBody] Timetable timetable)
        {
            SessionFactory          sessionFactory  = new SessionFactory();
            SessionsTable <Session> instanceSession = (SessionsTable <Session>)sessionFactory.GetSessionInstance();

            TimetableFactory           timetableFactory  = new TimetableFactory();
            TimetableTable <Timetable> instanceTimetable = (TimetableTable <Timetable>)timetableFactory.GetTimetableInstance();
            var list  = Request.Headers.ToList();
            var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty);

            if (token == null)
            {
                return("NOT LOGED");
            }
            var dispatcher = instanceSession.SelectDispatcherSession(token);
            var driver     = instanceSession.SelectDriverSession(token);
            var manager    = instanceSession.SelectManagerSession(token);

            if (dispatcher == null && driver == null && manager == null)
            {
                return("NOT EXISTING USER");
            }
            else if (timetable == null)
            {
                return("NO OBJECT");
            }

            instanceTimetable.Update(timetable);
            return("OK");
        }
Beispiel #5
0
        public string Put(int id, [FromBody] Request obj)
        {
            SessionFactory          sessionsFactory = new SessionFactory();
            SessionsTable <Session> instance        = (SessionsTable <Session>)sessionsFactory.GetSessionInstance();
            var list  = Request.Headers.ToList();
            var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty);

            if (token == null)
            {
                return("NOT LOGED");
            }
            var dispatcher = instance.SelectDispatcherSession(token);
            var driver     = instance.SelectDriverSession(token);
            var manager    = instance.SelectManagerSession(token);

            if (dispatcher == null && driver == null && manager == null)
            {
                return("NOT EXISTING USER");
            }
            else if (obj == null)
            {
                return("NO OBJECT");
            }
            RequestFactory         requestFactory  = new RequestFactory();
            RequestTable <Request> instanceRequest = (RequestTable <Request>)requestFactory.GetRequestInstance();

            instanceRequest.Update(obj);
            return("OK");
        }
Beispiel #6
0
        public Overview Get()
        {
            SessionFactory          sessionsFactory = new SessionFactory();
            SessionsTable <Session> instance        = (SessionsTable <Session>)sessionsFactory.GetSessionInstance();
            var list  = Request.Headers.ToList();
            var token = list.Where(a => a.Key == "token")?.FirstOrDefault().Value.FirstOrDefault()?.Replace("\"", string.Empty);

            if (token == null)
            {
                return(new Overview());
            }
            var dispatcher = instance.SelectDispatcherSession(token);
            var driver     = instance.SelectDriverSession(token);
            var manager    = instance.SelectManagerSession(token);

            if (dispatcher == null && driver == null && manager == null)
            {
                return(new Overview());
            }

            Overview obj = new Overview();

            RequestFactory         requestFactory  = new RequestFactory();
            RequestTable <Request> instanceRequest = (RequestTable <Request>)requestFactory.GetRequestInstance();
            var requests = instanceRequest.Select();

            obj.acceptedRequests = requests.Where(r => r.state == RequestState.ACCEPTED).Count();
            obj.declinedRequests = requests.Where(r => r.state == RequestState.DECLINED).Count();
            obj.newRequests      = requests.Where(r => r.state == RequestState.NEW).Count();


            decimal              salary         = 0;
            DriverFactory        driverFactory  = new DriverFactory();
            DriverTable <Driver> instanceDriver = (DriverTable <Driver>)driverFactory.GetDriverInstance();
            var listDrivers = instanceDriver.Select();

            obj.driverCount = listDrivers.Count();
            salary         += listDrivers.Sum(dr => dr.salary);

            DispatcherFactory            dispatcherFactory  = new DispatcherFactory();
            DispatcherTable <Dispatcher> instanceDispatcher = (DispatcherTable <Dispatcher>)dispatcherFactory.GetDispatcherInstance();
            var listDispatchers = instanceDispatcher.Select();

            obj.dispatcherCount = listDispatchers.Count();
            salary += listDispatchers.Sum(dis => dis.salary);

            obj.monthSalary = salary;


            VehicleFactory vehicleFactory  = new VehicleFactory();
            var            instanceVehicle = vehicleFactory.GetVehicleInstance();

            obj.vehicleCount = instanceVehicle.Select().Count();

            FailureFactory         failureFactory  = new FailureFactory();
            FailureTable <Failure> instanceFailure = (FailureTable <Failure>)failureFactory.GetFailureInstance();
            var      listFailures = instanceFailure.Select();
            DateTime lastMonth    = DateTime.Now.AddMonths(-1);

            obj.failurestInLastMonth = listFailures.Where(d => d.created > lastMonth).Count();
            obj.failures             = listFailures.Count();
            return(obj);
        }