예제 #1
0
        public string SaveCity(City city)
        {
            City aCity = cityGateway.IsExist(city);

            if (aCity == null)
            {
                int rowAffected = cityGateway.AddCity(city);
                if (rowAffected > 0)
                {
                    return("Saved Successfully");
                }
                else
                {
                    return("Saved Failed");
                }
            }
            return("City Name Already Existst");
        }
예제 #2
0
        public Message Save(City newCity)
        {
            Message message = new Message();

            if (newCity.Name.Length == 0)
            {
                message.Status  = "alert alert-warning";
                message.Details = "City name is required.";
                return(message);
            }
            bool isCityExists = IsCityExists(newCity);

            if (isCityExists)
            {
                message.Status  = "alert alert-danger";
                message.Details = "City name [" + newCity.Name + "] is already exists.";
                return(message);
            }

            if (newCity.About.Length == 0)
            {
                message.Status  = "alert alert-warning";
                message.Details = "About field name is required.";
                return(message);
            }

            if (newCity.Location.Length == 0)
            {
                message.Status  = "alert alert-warning";
                message.Details = "Location field name is required.";
                return(message);
            }

            if (newCity.Weather.Length == 0)
            {
                message.Status  = "alert alert-warning";
                message.Details = "Weather field name is required.";
                return(message);
            }

            if (newCity.CountryId == 0)
            {
                message.Status  = "alert alert-warning";
                message.Details = "Select a CountryDropDown of the city.";
                return(message);
            }

            try
            {
                aCityGateway.AddCity(newCity);
                message.Status  = "alert alert-success";
                message.Details = "City Added Successfully";
            }
            catch (SqlException ex)
            {
                message.Status  = "alert alert-danger";
                message.Details = ex.Message;
            }

            return(message);
        }