示例#1
0
        public int Create(IncidentAddRequest incidentAddRequest)
        {
            int returnVal = 0;

            var upvotes   = SqlInt32.Null;
            var downvotes = SqlInt32.Null;

            if (incidentAddRequest.Upvotes > 0)
            {
                upvotes = incidentAddRequest.Upvotes;
            }
            if (incidentAddRequest.Downvotes > 0)
            {
                downvotes = incidentAddRequest.Downvotes;
            }

            _dataProvider.ExecuteNonQuery(
                "incidents_create",
                inputParamMapper : delegate(SqlParameterCollection paramCol)
            {
                var parm = new SqlParameter
                {
                    ParameterName = "@Id",
                    SqlDbType     = SqlDbType.Int,
                    Direction     = ParameterDirection.Output
                };
                paramCol.Add(parm);

                paramCol.AddWithValue("@OffenseType", incidentAddRequest.OffenseType);
                paramCol.AddWithValue("@Incident", incidentAddRequest.Incident);
                paramCol.AddWithValue("@IncidentDate", incidentAddRequest.IncidentDate);
                paramCol.AddWithValue("@IncidentTime", incidentAddRequest.IncidentTime);
                paramCol.AddWithValue("@Location", incidentAddRequest.Location);
                paramCol.AddWithValue("@Upvotes", upvotes);
                paramCol.AddWithValue("@Downvotes", downvotes);
                paramCol.AddWithValue("@AdditionalDescription", string.IsNullOrEmpty(incidentAddRequest.AdditionalDescription) ? null : incidentAddRequest.AdditionalDescription);
            },
                returnParameters : delegate(SqlParameterCollection paramCol)
            {
                returnVal = (int)paramCol["@Id"].Value;
            }
                );

            return(returnVal);
        }
示例#2
0
 public HttpResponseMessage Create(IncidentAddRequest model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var resp = new ItemResponse <int>
             {
                 Item = _incidentService.Create(model)
             };
             return(Request.CreateResponse(HttpStatusCode.OK, resp));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
     }
 }