コード例 #1
0
        public ActionResult Index(FormCollection frmCollection, HttpPostedFileBase files)
        {
            AddPackageDataLayer objAddPackageDataLayer = new AddPackageDataLayer();

            Country objCountry = new Country
            {
                CountryName = frmCollection["Country"].ToString(),
                Latitude    = Convert.ToInt64(frmCollection["Countrylatitude"].ToString().Replace(".", "").Substring(0, 6)),
                Longitude   = Convert.ToInt64(frmCollection["Countrylongitude"].ToString().Replace(".", "").Substring(0, 6)),
            };

            Touristplace objTouristplace = new Touristplace
            {
                PlaceName   = frmCollection["TouristPlace"].ToString(),
                Latitude    = Convert.ToInt64(frmCollection["Placelatitude"].ToString().Replace(".", "").Substring(0, 6)),
                Longitude   = Convert.ToInt64(frmCollection["Placelongitude"].ToString().Replace(".", "").Substring(0, 6)),
                Description = frmCollection["Description"].ToString(),
                PhotoPath   = SaveImageToServer(files)
            };


            CountryTourist objCountryTourist = new CountryTourist
            {
                _Country      = objCountry,
                _Touristplace = objTouristplace
            };

            //Main Method to save Package
            ResponseType response = objAddPackageDataLayer.SavePackage(objCountryTourist);

            if (response == ResponseType.Sucess)
            {
                ViewBag.Status  = ResponseType.Sucess;
                ViewBag.Message = "Package saved successfully";
            }

            if (response == ResponseType.Error)
            {
                ViewBag.Status  = ResponseType.Error;
                ViewBag.Message = "Internal error occured";
            }

            if (response == ResponseType.Exists)
            {
                ViewBag.Status  = ResponseType.Exists;
                ViewBag.Message = "Package already exists";
            }


            return(View());
        }
コード例 #2
0
        public ResponseType SavePackage(CountryTourist objCountryTourist)
        {
            using (SqlConnection con = new SqlConnection(ConnectMSSql.GetConnectionString))
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("SpAddPackage", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@CountryName", objCountryTourist._Country.CountryName);
                    cmd.Parameters.AddWithValue("@CountryLatitude", objCountryTourist._Country.Latitude);
                    cmd.Parameters.AddWithValue("@CountryLongitude", objCountryTourist._Country.Longitude);

                    cmd.Parameters.AddWithValue("@PlaceName", objCountryTourist._Touristplace.PlaceName);
                    cmd.Parameters.AddWithValue("@PlaceLongitude", objCountryTourist._Touristplace.Longitude);
                    cmd.Parameters.AddWithValue("@PlaceLatitude", objCountryTourist._Touristplace.Latitude);
                    cmd.Parameters.AddWithValue("@PhotoPath", objCountryTourist._Touristplace.PhotoPath);
                    cmd.Parameters.AddWithValue("@Description", objCountryTourist._Touristplace.Description);

                    int Result = (int)cmd.ExecuteScalar();
                    if (Result == (int)ResponseType.Sucess)
                    {
                        return(ResponseType.Sucess);
                    }
                    else
                    {
                        return(ResponseType.Exists);
                    }
                }
                catch (Exception)
                {
                    return(ResponseType.Error);
                }
                finally
                {
                    con.Close();
                }
            }
        }