public List<UserModel> GetAllUsers(int pageNo, int records)
 {
     try
     {
         var loggedUserInfo = new UserInformation().GetCurrentUserInformation();
         return new Business.UserMethods().GetAllUsers(pageNo, records, loggedUserInfo.Role);
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
         {
             Content = new StringContent(string.Format("Service is currently unavailable.")),
             ReasonPhrase = "Service Unavailable "
         });
     }
 }
        public bool DeleteTimeZoneEntry(int timeZoneEntryId)
        {
            try
            {
                var userInfo = new UserInformation().GetCurrentUserInformation();

                var entryData = new TimeZoneEntryMethods().GetTimeZoneInformation(timeZoneEntryId);
                if (entryData == null)
                    throw new EntryNotFound();
                if (entryData.UserId != userInfo.UserId)
                    throw new UnAuthorize("User Not Authorize");

                return new Business.TimeZoneEntryMethods().DeleteTimeZoneEntry(timeZoneEntryId);
            }
            catch (EntryNotFound ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("No Entry with ID = {0}", timeZoneEntryId)),
                    ReasonPhrase = "Entry Not Found"
                });

            }
            catch (UnAuthorize ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent(string.Format("You are not authorize.")),
                    ReasonPhrase = "UnAuthorize"
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }
        public DataTableFilteredData GetUsersDataTable(UserManagementDataTable filterData)
        {
            try
            {
                var loggedUserInfo = new UserInformation().GetCurrentUserInformation();
                return new Business.UserMethods().GetUsersDataTable(filterData, loggedUserInfo.Role);

            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }
        public bool RemoveUser(int userId)
        {
            try
            {
                var loggedUserInfo = new UserInformation().GetCurrentUserInformation();
                var userInformation = new UserMethods().GetUserInformationBasedOnId(userId);

                if (Convert.ToInt32(userInformation.Role) > Convert.ToInt32(loggedUserInfo.Role))
                    throw new UnAuthorize();
                return new UserMethods().RemoveUser(userId);
            }
            catch (UnAuthorize ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent(string.Format("You are not authorize.")),
                    ReasonPhrase = "UnAuthorize"
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }
        public bool ModifyUserInformationAdmin(UserModel userInfo)
        {
            try
            {
                var loggedUserInfo = new UserInformation().GetCurrentUserInformation();
                var userInformation = new UserMethods().GetUserInformationBasedOnId(userInfo.UserId);
                //Checking Role Privilege
                if ((new Business.UserMethods().IsEmailExist(userInfo.Email) && userInformation.Email != userInfo.Email))
                    throw new HttpResponseException(HttpStatusCode.BadRequest);

                return new Business.UserMethods().ModifyUserInformationAdmin(userInfo);
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(string.Format("Email ID already exist")),
                    ReasonPhrase = "Bad Request"
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }
        public bool ModifyUserInformation(UserModel userInfo)
        {
            try
            {
                var userInfoSession = new UserInformation().GetCurrentUserInformation();
                if (IsEmailExist(userInfo.Email) && userInfoSession.Email != userInfo.Email)
                    throw new HttpResponseException(HttpStatusCode.BadRequest);

                userInfo.UserId = userInfoSession.UserId;
                return new Business.UserMethods().ModifyUserInformation(userInfo);
            }
            catch (HttpResponseException ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(string.Format("Email ID already exist.")),
                    ReasonPhrase = "Bad Request"
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
                {
                    Content = new StringContent(string.Format("Service is currently unavailable.")),
                    ReasonPhrase = "Service Unavailable "
                });
            }
        }
        public UserModel GetUserInformation()
        {
            try
            {
                var userInfo = new UserInformation().GetCurrentUserInformation();
                var userData = new Business.UserMethods().GetUserInformationBasedOnId(userInfo.UserId);
                if (userData == null)
                    throw new HttpResponseException(HttpStatusCode.NotFound);

                return userData;
            }
            catch (EntryNotFound ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content = new StringContent(string.Format("Entry not Found")),
                    ReasonPhrase = "Entry Not Found"
                });

            }
            catch (HttpResponseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(HttpStatusCode.ServiceUnavailable);
            }
        }
 public List<UserTimeZoneEntryModel> GetUserTimeZoneInformation(int userId, int pageNo, int noOfUserRecords, int timeZoneRecordPageNo, int timeZoneRecordToGet)
 {
     try
     {
         var userInfo = new UserInformation().GetCurrentUserInformation();
         var data = new Business.TimeZoneEntryMethods().GetUserTimeZoneInformation(userId, pageNo, noOfUserRecords, timeZoneRecordPageNo, timeZoneRecordToGet, userInfo.Role);
         if (data == null)
             throw new EntryNotFound();
         return data;
     }
     catch (EntryNotFound ex)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
         {
             Content = new StringContent(string.Format("No Entry Found.")),
             ReasonPhrase = "Entry Not Found"
         });
     }
     catch (Exception ex)
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
         {
             Content = new StringContent(string.Format("Service is currently unavailable.")),
             ReasonPhrase = "Service Unavailable "
         });
     }
 }