示例#1
0
        public static int AddHospital(HospitalsAddRequest model)
        {
            var id = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Hospitals_Insert",
                                         inputParamMapper : delegate(SqlParameterCollection InsertHospital)
            {
                //InsertHospital.AddWithValue("@HospitalId", model.HospitalId);
                InsertHospital.AddWithValue("@Name", model.Name);
                InsertHospital.AddWithValue("@Abbrev", model.Abbrev);
                InsertHospital.AddWithValue("@Address", model.Address);
                InsertHospital.AddWithValue("@City", model.City);
                InsertHospital.AddWithValue("@State", model.State);
                InsertHospital.AddWithValue("@ZipCode", model.ZipCode);

                SqlParameter param = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                param.Direction    = System.Data.ParameterDirection.Output;

                InsertHospital.Add(param);
            },

                                         returnParameters : delegate(SqlParameterCollection par)
            {
                int.TryParse(par["@Id"].Value.ToString(), out id);
            }
                                         );

            return(id);
        }
        public HttpResponseMessage AddHospital(HospitalsAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <int> response = new ItemResponse <int>();

            response.Item = HospitalsService.AddHospital(model);
            return(Request.CreateResponse(response));
        }