public new List <Device> GetDeviceListFromCompanyID(int companyID)
        {
            try
            {
                string url  = IoC.API_URL + "device/getDevicesByCompanyID";
                string json = companyID.ToString();

                HttpWebRequest       request = Connect_dl.BuildRequest(url, "POST", json);
                Tuple <bool, string> result  = ValidateResponse(request);

                if (result.Item1)
                {
                    List <Device> devices = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Device> >(result.Item2);
                    return(devices);
                }
                else
                {
                    //return empty list
                    List <Device> devices = new List <Device>();
                    return(devices);
                }
            }
            catch
            {
                return(null);
            }
        }
        public new Device Update()
        {
            try
            {
                string url  = IoC.API_URL + "device/updateAndReturn";
                string json = Connect_dl.BuildJson(this, true);

                HttpWebRequest       request = Connect_dl.BuildRequest(url, "POST", json);
                Tuple <bool, string> result  = ValidateResponse(request);

                if (result.Item1)
                {
                    Device deviceUpdate = Newtonsoft.Json.JsonConvert.DeserializeObject <Device>(result.Item2);
                    return(deviceUpdate);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
        public new Device Fill()
        {
            try
            {
                string url  = IoC.API_URL + "device/fill";
                string json = this.DeviceID.ToString();

                HttpWebRequest       request = Connect_dl.BuildRequest(url, "POST", json);
                Tuple <bool, string> result  = ValidateResponse(request);

                if (result.Item1)
                {
                    Device deviceFill = Newtonsoft.Json.JsonConvert.DeserializeObject <Device>(result.Item2);
                    return(deviceFill);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
        private Tuple <bool, string> ValidateResponse(HttpWebRequest request)
        {
            if (request != null)
            {
                Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                HttpStatusCode code         = response.FirstOrDefault().Key;
                string         httpResponse = response.FirstOrDefault().Value;

                if (code == HttpStatusCode.OK)
                {
                    return(new Tuple <bool, string>(true, httpResponse));
                }
                else
                {
                    if (code == HttpStatusCode.Conflict)
                    {
                        return(new Tuple <bool, string>(false, ""));
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            else
            {
                throw new Exception();
            }
        }
        public new ParkingLot Create()
        {
            string url  = IoC.API_URL + "parkingLot/create";
            string json = Connect_dl.BuildJson(this);

            HttpWebRequest request = Connect_dl.BuildRequest(url, "POST", json);

            return(ValidateResponse("Create", request) as ParkingLot);
        }
        public new bool?Delete()
        {
            string url  = IoC.API_URL + "parkingLot/delete";
            string json = this.LotID.ToString();

            HttpWebRequest request = Connect_dl.BuildRequest(url, "POST", json);

            return(ValidateResponse("Delete", request) as bool?);
        }
        public new List <Device> GetCamerasDeployed()
        {
            string url  = IoC.API_URL + "parkingLot/getCamerasDeployedAtParkingLot";
            string json = Connect_dl.BuildJson(this);

            HttpWebRequest request = Connect_dl.BuildRequest(url, "POST", json);

            return(ValidateResponse("GetCamerasDeployed", request) as List <Device>);
        }
        public new List <ParkingLot> GetParkingLotListFromCompanyID(int companyID)
        {
            string url  = IoC.API_URL + "parkingLot/getParkingLotsByCompanyId";
            string json = companyID.ToString();

            HttpWebRequest request = Connect_dl.BuildRequest(url, "POST", json);

            return(ValidateResponse("GetParkingLotListFromCompanyID", request) as List <ParkingLot>);
        }
        public new ParkingLot Fill()
        {
            ParkingLot parkingLot = new ParkingLot();

            parkingLot.LotID = this.LotID;

            string url  = IoC.API_URL + "parkingLot/fill";
            string json = this.LotID.ToString();

            HttpWebRequest request = Connect_dl.BuildRequest(url, "POST", json);

            return(ValidateResponse("Fill", request) as ParkingLot);
        }
        public new bool?SignUp()
        {
            string url  = IoC.API_URL + "company/signUp";
            string json = Connect_dl.BuildJson(this);

            HttpWebRequest request = Connect_dl.BuildRequest(url, "POST", json);

            if (request != null)
            {
                Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                HttpStatusCode code         = response.FirstOrDefault().Key;
                string         httpResponse = response.FirstOrDefault().Value;

                if (code == HttpStatusCode.OK)
                {
                    //clear company in IoC, return true
                    Company company = new Company();
                    IoC.CurrentCompany = company;
                    return(true);
                }
                else
                {
                    if (httpResponse == "Company already exists with specified username.")
                    {
                        //clear company, return false for incorrect username/password
                        IoC.ClearSessionIoC();
                        return(false);
                    }
                    else
                    {
                        //clear company, return null for server error
                        IoC.ClearSessionIoC();
                        return(null);
                    }
                }
            }
            else
            {
                //clear company, return null for server error
                IoC.ClearSessionIoC();
                return(null);
            }
        }
        public new bool?Login()
        {
            string url  = IoC.API_URL + "company/login";
            string json = Connect_dl.BuildJson(this);

            HttpWebRequest request = Connect_dl.BuildRequest(url, "POST", json);

            if (request != null)
            {
                Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                HttpStatusCode code         = response.FirstOrDefault().Key;
                string         httpResponse = response.FirstOrDefault().Value;

                if (code == HttpStatusCode.OK)
                {
                    //save company in IoC, return true
                    Company currentCompany = Newtonsoft.Json.JsonConvert.DeserializeObject <Company>(httpResponse);
                    IoC.CurrentCompany = currentCompany;
                    return(true);
                }
                else
                {
                    if (httpResponse == "Incorrect Username or Password")
                    {
                        //clear company, return false for incorrect username/password
                        IoC.ClearSessionIoC();
                        return(false);
                    }
                    else
                    {
                        //clear company, return null for server error
                        IoC.ClearSessionIoC();
                        return(null);
                    }
                }
            }
            else
            {
                //clear company, return null for server error
                IoC.ClearSessionIoC();
                return(null);
            }
        }
        public new bool SaveSpots(List <Spot> spotList)
        {
            try
            {
                string url  = IoC.API_URL + "device/saveSpots";
                string json = JsonConvert.SerializeObject(spotList);

                HttpWebRequest       request = Connect_dl.BuildRequest(url, "POST", json);
                Tuple <bool, string> result  = ValidateResponse(request);

                if (result.Item1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
        public new bool ClearImage()
        {
            try
            {
                string url  = IoC.API_URL + "device/clearImageFromDatabase";
                string json = this.DeviceID.ToString();

                HttpWebRequest       request = Connect_dl.BuildRequest(url, "POST", json);
                Tuple <bool, string> result  = ValidateResponse(request);

                if (result.Item1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
        public new string GetEncodedImageString()
        {
            try
            {
                string url  = IoC.API_URL + "device/retrieveImageString";
                string json = this.DeviceID.ToString();

                HttpWebRequest       request = Connect_dl.BuildRequest(url, "POST", json);
                Tuple <bool, string> result  = ValidateResponse(request);

                if (result.Item1)
                {
                    return(result.Item2);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
        private object ValidateResponse(string method, HttpWebRequest request)
        {
            switch (method)
            {
            case "Fill":
                ParkingLot parkingLotFill = new ParkingLot();
                if (request != null)
                {
                    Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                    HttpStatusCode code         = response.FirstOrDefault().Key;
                    string         httpResponse = response.FirstOrDefault().Value;

                    if (code == HttpStatusCode.OK)
                    {
                        //return parkingLot
                        parkingLotFill = Newtonsoft.Json.JsonConvert.DeserializeObject <ParkingLot>(httpResponse);
                        return(parkingLotFill);
                    }
                    else
                    {
                        //return parkingLots with no info
                        return(parkingLotFill);
                    }
                }
                else
                {
                    //return parkingLots with no info
                    return(parkingLotFill);
                }

            case "GetParkingLotListFromCompanyID":
                List <ParkingLot> parkingLots = new List <ParkingLot>();
                if (request != null)
                {
                    Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                    HttpStatusCode code         = response.FirstOrDefault().Key;
                    string         httpResponse = response.FirstOrDefault().Value;

                    if (code == HttpStatusCode.OK)
                    {
                        //return devices
                        parkingLots = Newtonsoft.Json.JsonConvert.DeserializeObject <List <ParkingLot> >(httpResponse);
                        return(parkingLots);
                    }
                    else
                    {
                        if (httpResponse == "No devices are linked to this company.")
                        {
                            //Return empty list
                            return(parkingLots);
                        }
                        else
                        {
                            //return null
                            return(null);
                        }
                    }
                }
                else
                {
                    //return null
                    return(null);
                }

            case "UpdateParkingLot":
                ParkingLot parkingLotUpdate = new ParkingLot();
                if (request != null)
                {
                    Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                    HttpStatusCode code         = response.FirstOrDefault().Key;
                    string         httpResponse = response.FirstOrDefault().Value;

                    if (code == HttpStatusCode.OK)
                    {
                        //return parking lot
                        parkingLotUpdate = Newtonsoft.Json.JsonConvert.DeserializeObject <ParkingLot>(httpResponse);
                        return(parkingLotUpdate);
                    }
                    else
                    {
                        //return null
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }

            case "GetCamerasDeployed":
                List <Device> devicesToLot = new List <Device>();
                if (request != null)
                {
                    Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                    HttpStatusCode code         = response.FirstOrDefault().Key;
                    string         httpResponse = response.FirstOrDefault().Value;

                    if (code == HttpStatusCode.OK)
                    {
                        //return parking lot
                        devicesToLot = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Device> >(httpResponse);
                        return(devicesToLot);
                    }
                    else
                    {
                        if (httpResponse == "No deployed devices found")
                        {
                            //Return empty list
                            return(devicesToLot);
                        }
                        else
                        {
                            //return null
                            return(null);
                        }
                    }
                }
                else
                {
                    return(null);
                }

            case "Delete":
                bool?deleteResult = false;
                if (request != null)
                {
                    Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                    HttpStatusCode code         = response.FirstOrDefault().Key;
                    string         httpResponse = response.FirstOrDefault().Value;

                    if (code == HttpStatusCode.OK)
                    {
                        //return parking lot
                        deleteResult = Newtonsoft.Json.JsonConvert.DeserializeObject <bool?>(httpResponse);
                        return(deleteResult);
                    }
                    else
                    {
                        if (httpResponse == "Devices still deployed to parking lot.")
                        {
                            //Return empty list
                            return(false);
                        }
                        else
                        {
                            //return null
                            return(null);
                        }
                    }
                }
                else
                {
                    return(null);
                }

            case "Create":
                ParkingLot parkingLotCreate = new ParkingLot();
                if (request != null)
                {
                    Dictionary <HttpStatusCode, string> response = Connect_dl.GetResponse(request);
                    HttpStatusCode code         = response.FirstOrDefault().Key;
                    string         httpResponse = response.FirstOrDefault().Value;

                    if (code == HttpStatusCode.OK)
                    {
                        //return parking lot
                        parkingLotCreate = Newtonsoft.Json.JsonConvert.DeserializeObject <ParkingLot>(httpResponse);
                        return(parkingLotCreate);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }

            default:
                return(false);
            }
        }