public string CheckIfAirportsExists(ACRF_AirportsModel objModel)
        {
            string result = "";

            try
            {
                string sqlstr = "Select * from ACRF_Airports Where ISNULL(Airports,'')=@Airports and Isnull(Id,0)!=@Id "
                                + " and CountryId=@CountryId and ShortCode=@ShortCode ";

                var connection = gConnection.Connection();
                connection.Open();
                SqlCommand cmd = new SqlCommand(sqlstr, connection);
                cmd.Parameters.AddWithValue("@Airports", objModel.Airports);
                cmd.Parameters.AddWithValue("@CountryId", objModel.CountryId);
                cmd.Parameters.AddWithValue("@ShortCode", objModel.ShortCode);
                cmd.Parameters.AddWithValue("@Id", objModel.Id);
                SqlDataReader sdr = cmd.ExecuteReader();

                while (sdr.Read())
                {
                    result = "Airports already exists!";
                }
                sdr.Close();


                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }
            return(result);
        }
        public string UpdateAirports(ACRF_AirportsModel objModel)
        {
            string result = "Error on Updating Airports!";

            try
            {
                result = CheckIfAirportsExists(objModel);
                if (result == "")
                {
                    var connection = gConnection.Connection();
                    connection.Open();
                    SqlCommand     cmd = connection.CreateCommand();
                    SqlTransaction transaction;
                    transaction     = connection.BeginTransaction();
                    cmd.Transaction = transaction;
                    cmd.Connection  = connection;
                    try
                    {
                        string sqlstr = "";
                        sqlstr = "update ACRF_Airports set Airports=@Airports, ShortCode=@ShortCode, CountryId=@CountryId,"
                                 + " UpdatedBy=@UpdatedBy,UpdatedOn=@UpdatedOn where Id=@Id";
                        cmd.CommandText = sqlstr;
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@Airports", objModel.Airports);
                        cmd.Parameters.AddWithValue("@ShortCode", objModel.ShortCode);
                        cmd.Parameters.AddWithValue("@CountryId", objModel.CountryId);
                        cmd.Parameters.AddWithValue("@Id", objModel.Id);
                        cmd.Parameters.AddWithValue("@UpdatedBy", objModel.UpdatedBy);
                        cmd.Parameters.AddWithValue("@UpdatedOn", StandardDateTime.GetDateTime());
                        cmd.ExecuteNonQuery();


                        transaction.Commit();
                        connection.Close();
                        result = "Airports Updated Successfully!";
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        connection.Close();
                        Global.ErrorHandlerClass.LogError(ex);
                        result = ex.Message;
                    }
                }
                else
                {
                    return(result);
                }
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }

            return(result);
        }
        public IHttpActionResult ViewOneAirports(int Id)
        {
            ACRF_AirportsModel objList = new ACRF_AirportsModel();

            try
            {
                objList = objAirportsVM.GetOneAirports(Id);
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }

            return(Ok(new { results = objList }));
        }
        public List <ACRF_AirportsModel> ListAirports()
        {
            List <ACRF_AirportsModel> objList = new List <ACRF_AirportsModel>();

            try
            {
                string sqlstr = "select Id, isnull(ShortCode,'') as ShortCode, isnull(Airports,'') as Airports, isnull(CountryId,0) as CountryId, "
                                + " isnull(CreatedBy,'') as CreatedBy, isnull(createdon,'') as CreatedOn,  "
                                + " isnull(updatedby,'') as updatedby, isnull(updatedon,'') as updatedon from ACRF_Airports order by Id";

                var connection = gConnection.Connection();
                connection.Open();
                SqlCommand cmd = new SqlCommand(sqlstr, connection);
                cmd.CommandType = System.Data.CommandType.Text;
                SqlDataReader sdr = cmd.ExecuteReader();

                while (sdr.Read())
                {
                    ACRF_AirportsModel tempobj = new ACRF_AirportsModel();
                    tempobj.Id        = Convert.ToInt32(sdr["Id"].ToString());
                    tempobj.Airports  = sdr["Airports"].ToString();
                    tempobj.ShortCode = sdr["ShortCode"].ToString();
                    tempobj.CountryId = Convert.ToInt32(sdr["CountryId"].ToString());
                    tempobj.CreatedBy = sdr["CreatedBy"].ToString();
                    tempobj.CreatedOn = Convert.ToDateTime(sdr["CreatedOn"].ToString());
                    objList.Add(tempobj);
                }
                sdr.Close();


                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }
            return(objList);
        }
        public IHttpActionResult AddAirports(ACRF_AirportsModel objModel)
        {
            string result = "";

            if (ModelState.IsValid)
            {
                try
                {
                    objModel.CreatedBy = GlobalFunction.getLoggedInUser(Request.Headers.GetValues("Token").First());
                    result             = objAirportsVM.CreateAirports(objModel);
                }
                catch (Exception ex)
                {
                    ErrorHandlerClass.LogError(ex);
                    result = ex.Message;
                }
            }
            else
            {
                result = "Enter Valid Mandatory Fields";
            }
            return(Ok(new { results = result }));
        }
        public ACRF_AirportsModel GetOneAirports(int Id)
        {
            ACRF_AirportsModel objList = new ACRF_AirportsModel();

            try
            {
                string sqlstr = "select Id, isnull(ShortCode,'') as ShortCode, isnull(Airports,'') as Airports, isnull(CountryId,0) as CountryId, "
                                + " isnull(CreatedBy,'') as CreatedBy, isnull(createdon,'') as CreatedOn,  "
                                + " isnull(updatedby,'') as updatedby, isnull(updatedon,'') as updatedon from ACRF_Airports where Id=@Id";

                var connection = gConnection.Connection();
                connection.Open();
                SqlCommand cmd = new SqlCommand(sqlstr, connection);
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.Parameters.AddWithValue("@Id", Id);
                SqlDataReader sdr = cmd.ExecuteReader();

                while (sdr.Read())
                {
                    objList.Id        = Convert.ToInt32(sdr["Id"].ToString());
                    objList.Airports  = sdr["Airports"].ToString();
                    objList.ShortCode = sdr["ShortCode"].ToString();
                    objList.CountryId = Convert.ToInt32(sdr["CountryId"].ToString());
                    objList.CreatedBy = sdr["CreatedBy"].ToString();
                    objList.CreatedOn = Convert.ToDateTime(sdr["CreatedOn"].ToString());
                }
                sdr.Close();


                connection.Close();
            }
            catch (Exception ex)
            {
                ErrorHandlerClass.LogError(ex);
            }
            return(objList);
        }