public int setCreatePhone(PhoneTO objPhone, ref int codError, ref string msjError) { List <PhoneTO> objList = new List <PhoneTO>(); try { using (SqlConnection sql = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand("createPhone", sql)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@idUser", SqlDbType.Int).Value = objPhone.IdUser; cmd.Parameters.Add("@idStatus", SqlDbType.Int).Value = objPhone.IdStatus; cmd.Parameters.Add("@phone", SqlDbType.BigInt).Value = objPhone.Phone; cmd.Parameters.Add("@area", SqlDbType.Int).Value = objPhone.Area; sql.Open(); var ds = new DataSet(); var da = new SqlDataAdapter(cmd); da.Fill(ds); if (ds.Tables.Count == 1) { List <ResultTO> error = ds.Tables[0].AsEnumerable() .Select(dataRow => new ResultTO { Result = dataRow.Field <int>("result"), Msg = dataRow.Field <string>("msg") }).ToList(); codError = 1; msjError = error.FirstOrDefault().Msg; return(0); } List <ResultTO> results = ds.Tables[1].AsEnumerable() .Select(dataRow => new ResultTO { Result = dataRow.Field <int>("result"), Msg = dataRow.Field <string>("msg") }).ToList(); objList = ds.Tables[0].AsEnumerable() .Select(dataRow => new PhoneTO { IdPhone = dataRow.Field <int>("idPhone") }).ToList(); } } return(objList.FirstOrDefault().IdPhone); } catch (Exception e) { codError = 0; msjError = e.Message; return(0); } }
public IHttpActionResult setCreatePhone(PhoneTO objPhone) { int codError = 1; string msjError = ""; PhoneServices objServicio = new PhoneServices(); var result = objServicio.setCreatePhone(objPhone, ref codError, ref msjError); if (codError == 1) { return(Ok(result)); } return(BadRequest(msjError)); }