コード例 #1
0
        public IActionResult AddCity(AddCityRequestModel addCity)
        {
            try
            {
                bool   status = false;
                string message;

                AddCityResponseModel cityResponse = _cityBusiness.AddCity(addCity);

                if (cityResponse != null)
                {
                    if (cityResponse.ErrorResponse.ErrorStatus)
                    {
                        message = cityResponse.ErrorResponse.Message;
                        return(Ok(new { status, message }));
                    }
                    else
                    {
                        status  = true;
                        message = "City Has Been Successfully Added to State.";
                        CityAddResponseModel data = cityResponse.CityAdd;
                        return(Ok(new { status, message, data }));
                    }
                }

                message = "Unable to Add City.";
                return(Ok(new { status, message }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { e.Message }));
            }
        }
コード例 #2
0
        /// <summary>
        /// It Fetch the list of all Cities.
        /// </summary>
        /// <returns>List of Cities</returns>
        public List <CityAddResponseModel> GetAllCity()
        {
            try
            {
                int           statusCode;
                SqlDataReader reader;
                List <CityAddResponseModel> cities = null;

                using (SqlConnection connection = new SqlConnection(sqlConnection))
                {
                    SqlCommand sqlCommand = new SqlCommand("spCity", connection)
                    {
                        CommandType = System.Data.CommandType.StoredProcedure
                    };
                    sqlCommand.Parameters.AddWithValue("@CityId", -1);
                    sqlCommand.Parameters.AddWithValue("@Name", "");
                    sqlCommand.Parameters.AddWithValue("@StateId", -1);
                    sqlCommand.Parameters.AddWithValue("@ActionType", "GetAllCity");

                    SqlParameter cmdExecuteSuccess = sqlCommand.Parameters.Add("@return_value", System.Data.SqlDbType.Int);
                    cmdExecuteSuccess.Direction = System.Data.ParameterDirection.ReturnValue;

                    connection.Open();

                    reader     = sqlCommand.ExecuteReader();
                    statusCode = Convert.ToInt32(sqlCommand.Parameters["@return_Value"].Value);

                    if (statusCode == 0)
                    {
                        cities = new List <CityAddResponseModel>();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                CityAddResponseModel cityAdd = new CityAddResponseModel
                                {
                                    CityId     = Convert.ToInt32(reader[0]),
                                    Name       = reader[1].ToString(),
                                    StateId    = Convert.ToInt32(reader[2]),
                                    CreatedAt  = Convert.ToDateTime(reader[3]),
                                    ModifiedAt = Convert.ToDateTime(reader[4])
                                };
                                cities.Add(cityAdd);
                            }
                        }
                    }
                }

                return(cities);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #3
0
        /// <summary>
        /// It fetchs the Specified city Details
        /// </summary>
        /// <param name="CityId">City Id</param>
        /// <returns>If fetching successfull, it return CityAddResponseModel or else null</returns>
        public CityAddResponseModel GetCityById(int CityId)
        {
            try
            {
                SqlDataReader        reader;
                CityAddResponseModel city = null;

                using (SqlConnection connection = new SqlConnection(sqlConnection))
                {
                    SqlCommand sqlCommand = new SqlCommand("spCity", connection)
                    {
                        CommandType = System.Data.CommandType.StoredProcedure
                    };
                    sqlCommand.Parameters.AddWithValue("@CityId", CityId);
                    sqlCommand.Parameters.AddWithValue("@Name", "");
                    sqlCommand.Parameters.AddWithValue("@StateId", -1);
                    sqlCommand.Parameters.AddWithValue("@ActionType", "GetCityById");

                    connection.Open();

                    reader = sqlCommand.ExecuteReader();

                    if (reader.HasRows)
                    {
                        city = new CityAddResponseModel();

                        while (reader.Read())
                        {
                            city.CityId     = Convert.ToInt32(reader[0]);
                            city.Name       = reader[1].ToString();
                            city.StateId    = Convert.ToInt32(reader[2]);
                            city.CreatedAt  = Convert.ToDateTime(reader[3]);
                            city.ModifiedAt = Convert.ToDateTime(reader[4]);
                        }
                    }
                }

                return(city);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #4
0
        public IActionResult GetCityById(int CityId)
        {
            try
            {
                bool   status = false;
                string message;

                CityAddResponseModel data = _cityBusiness.GetCityById(CityId);
                if (data != null)
                {
                    status  = true;
                    message = "City Details has been Successfully fetched";
                    return(Ok(new { status, message, data }));
                }

                message = "Unable to get the specificed City Details";
                return(Ok(new { status, message }));
            }
            catch (Exception e)
            {
                return(BadRequest(new { e.Message }));
            }
        }