Exemplo n.º 1
0
        public int setCreateOrderHistory(OrderHistoryTO objOrderHistory, ref int codError, ref string msjError)
        {
            List <OrderHistoryTO> objList = new List <OrderHistoryTO>();

            try
            {
                using (SqlConnection sql = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand cmd = new SqlCommand("createOrderHistory", sql))
                    {
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;

                        cmd.Parameters.Add("@idOrder", SqlDbType.Int).Value  = objOrderHistory.IdOrder;
                        cmd.Parameters.Add("@idStatus", SqlDbType.Int).Value = objOrderHistory.IdStatus;


                        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 OrderHistoryTO
                        {
                            IdHistory = dataRow.Field <int>("idHistory")
                        }).ToList();
                    }
                }
                return(objList.FirstOrDefault().IdHistory);
            }
            catch (Exception e)
            {
                codError = 0;
                msjError = e.Message;
                return(0);
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult setCreateOrderHistory(OrderHistoryTO ordr)
        {
            int           codError    = 1;
            string        msjError    = "";
            OrderServices objServicio = new OrderServices();
            var           result      = objServicio.setCreateOrderHistory(ordr, ref codError, ref msjError);

            if (codError == 1)
            {
                return(Ok(result));
            }
            return(BadRequest(msjError));
        }