public HttpResponseMessage AddressInsert(AddressRequiredRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            int AddressId = _AddressService.InsertAddress(model);

            var response = new ItemResponse <int> {
                Item = AddressId
            };

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Esempio n. 2
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public int InsertAddress(AddressRequiredRequest model)
        {
            int Id = 0;

            string addressString = String.Concat(model.Address1, ", ", model.City, ",  "
                                                 , model.State, ", ", model.ZipCode);

            LatLngDomain latlng = AddressGetLatLng(addressString);

            model.Latitude  = latlng.Latitude;
            model.Longitude = latlng.Longitude;

            try
            {
                DataProvider.ExecuteNonQuery(GetConnection, "dbo.Address_Insert"
                                             , inputParamMapper : delegate(SqlParameterCollection paramCollection)
                {
                    paramCollection.AddWithValue("@CompanyId", model.CompanyId);
                    paramCollection.AddWithValue("@Date", DateTime.Now);
                    paramCollection.AddWithValue("@Address1", model.Address1);
                    paramCollection.AddWithValue("@City", model.City);
                    paramCollection.AddWithValue("@State", model.State);
                    paramCollection.AddWithValue("@ZipCode", model.ZipCode);
                    paramCollection.AddWithValue("@Latitude", model.Latitude);
                    paramCollection.AddWithValue("@Longitude", model.Longitude);
                    paramCollection.AddWithValue("@Slug", model.Slug);
                    paramCollection.AddWithValue("@AddressType", model.AddressType);

                    var p       = new SqlParameter("@id", System.Data.SqlDbType.Int);
                    p.Direction = System.Data.ParameterDirection.Output;

                    paramCollection.Add(p);
                }, returnParameters : delegate(SqlParameterCollection param)
                {
                    int.TryParse(param["@Id"].Value.ToString(), out Id);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Id);
        }