コード例 #1
0
        public PromoteAnswer promote(PromoteRequest r)
        {
            using (var con = new SqlConnection(constr))
                using (var com = new SqlCommand())
                {
                    com.Connection = con;
                    con.Open();
                    var tran = con.BeginTransaction();
                    com.Transaction = tran;
                    try
                    {
                        int id = 0;

                        com.CommandText = "Promote";
                        com.CommandType = CommandType.StoredProcedure;
                        com.Parameters.AddWithValue("@Semester", r.Semester);
                        com.Parameters.AddWithValue("@Sname", r.Studies);
                        com.Parameters.AddWithValue("@EnrId", SqlDbType.Int);
                        com.Parameters["@EnrId"].Direction = ParameterDirection.Output;

                        com.ExecuteNonQuery();

                        id = (int)com.Parameters["@EnrId"].Value;

                        if (id == 0)
                        {
                            code = 404;
                            return(null);
                        }

                        com.Parameters.Clear();
                        com.CommandType = CommandType.Text;
                        com.CommandText = "Select * From Enrollment WHERE IdEnrollment = @Id";
                        com.Parameters.AddWithValue("Id", id);
                        var           dr  = com.ExecuteReader();
                        PromoteAnswer ans = new PromoteAnswer();
                        ans.EnrId     = id;
                        ans.IdStudies = (int)dr["IdStudy"];
                        ans.Semester  = (int)dr["Semester"];
                        ans.StartDate = (DateTime)dr["StartDate"];
                        return(ans);
                    }
                    catch (SqlException e)
                    {
                        tran.Rollback();
                        code    = 400;
                        message = e.Message;
                        return(null);
                    }
                }
        }
コード例 #2
0
        public IActionResult promote(PromoteRequest r)
        {
            PromoteAnswer ret = ienr.promote(r);

            if (ret == null)
            {
                if (ienr.code == 404)
                {
                    return(NotFound());
                }
                return(BadRequest(ienr.message));
            }
            else
            {
                return(Created("", ret));
            }
        }