public IHttpActionResult GetPage([FromUri] string senderID)
        {
            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            try
            {
                if (DbAdmin.Exists(senderID))
                {
                    return(Ok("./Content/partials/adminProfile.html"));
                }
                else if (DbDriver.Exists(senderID))
                {
                    return(Ok("./Content/partials/driverProfile.html"));
                }
                else if (DbCustomer.Exists(senderID))
                {
                    return(Ok("./Content/partials/customerProfile.html"));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'Login()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }
        }
        public IHttpActionResult GetDriver([FromUri] string senderID, [FromUri] string userIdToGet)
        {
            Driver result = null;

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            try
            {
                if (DbDriver.Exists(userIdToGet))
                {
                    if (!DbAdmin.Exists(senderID) || senderID != userIdToGet)
                    {
                        return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher nor the user whose information are requested."));
                    }

                    result = DbDriver.GetSingleEntityByKey(userIdToGet);
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'GetDriver()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
        // PUT api/drivers/5
        public IHttpActionResult PutDriver([FromUri] string senderID, [FromBody] DriverModel driverModel)
        {
            bool result = false;

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }

            if (DbDriver.Exists(driverModel.Username))
            {
                if (!DbAdmin.Exists(senderID) || senderID != driverModel.Username)
                {
                    return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher nor a user to be modified."));
                }


                try
                {
                    Driver driver = new Driver(driverModel.Username, driverModel.Password)
                    {
                        FirstName       = driverModel.FirstName,
                        LastName        = driverModel.LastName,
                        Gender          = driverModel.Gender,
                        JMBG            = driverModel.JMBG,
                        Phone           = driverModel.Phone,
                        Email           = driverModel.Email,
                        DriversLocation = DbLocation.GetSingleEntityByKey(driverModel.DriversLocationID),
                        DriversVehicle  = DbVehicle.GetSingleEntityByKey(driverModel.DriversVehicleID),
                    };
                    driverModel.TaxiDrivesIDs.ForEach(td => driver.TaxiDrives.Add(DbTaxiDrive.GetSingleEntityByKey(td)));

                    result = DbDriver.Modify(driver);
                }
                catch (Exception e)
                {
                    Trace.Write($"Error on 'PutDriver()'. Error message: {e.Message}");
                    Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                    return(InternalServerError(e));
                }
            }

            if (result)
            {
                return(Ok(driverModel));
            }
            else
            {
                return(NotFound());
            }
        }
        public IHttpActionResult Login([FromBody] LoginModel loginModel)
        {
            if (LoggedUsers.Contains(loginModel.Username))
            {
                return(Content(HttpStatusCode.Conflict, $"User '{loginModel.Username}' already logged in."));
            }

            IUser result = null;

            try
            {
                if (DbAdmin.Exists(loginModel.Username))
                {
                    result = DbAdmin.GetSingleEntityByKey(loginModel.Username);
                }
                else if (DbDriver.Exists(loginModel.Username))
                {
                    result = DbDriver.GetSingleEntityByKey(loginModel.Username);
                }
                else if (DbCustomer.Exists(loginModel.Username))
                {
                    result = DbCustomer.GetSingleEntityByKey(loginModel.Username);
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'Login()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result == null)
            {
                return(NotFound());
            }

            if (result.Password.Equals(loginModel.Password))
            {
                LoggedUsers.Add(loginModel.Username);
                return(Ok(result));
            }
            else
            {
                return(BadRequest($"Entered password did not match the required one for user '{loginModel.Username}'."));
            }
        }
        // DELETE api/drivers/5
        public IHttpActionResult DeleteUser([FromUri] string senderID, [FromUri] string userToDelete)
        {
            bool result = false;

            if (!LoggedUsers.Contains(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not logged in."));
            }
            else if (!DbAdmin.Exists(senderID))
            {
                return(Content(HttpStatusCode.Unauthorized, "Not a dispatcher."));
            }

            try
            {
                if (DbAdmin.Exists(userToDelete))
                {
                    //TODO: sta ako obrise samog sebe logout?
                    result = DbAdmin.Delete(userToDelete);
                }
                else if (DbDriver.Exists(userToDelete))
                {
                    result = DbDriver.Delete(userToDelete);
                }
                else if (DbCustomer.Exists(userToDelete))
                {
                    result = DbCustomer.Delete(userToDelete);
                }
            }
            catch (Exception e)
            {
                Trace.Write($"Error on 'DeleteUser()'. Error message: {e.Message}");
                Trace.Write($"[STACK_TRACE] {e.StackTrace}");
                return(InternalServerError(e));
            }

            if (result)
            {
                return(Ok());
            }
            else
            {
                return(NotFound());
            }
        }