示例#1
0
        public bool Handle(int courseId, CreateCourseCommand request)
        {
            var model = request.Adapt <Model.MedicalCourse>();

            using (MySqlConnection conn = _context.GetConnection())
            {
                conn.Open();

                string query = string.Format("update courses set course_name='{1}', qualification='{2}' where course_id={0}",
                                             courseId.ToString(),
                                             model.Name,
                                             model.Qualification);

                MySqlCommand cmd = new MySqlCommand(query, conn);

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    string s = ex.Message;
                    return(false);
                }
                finally
                {
                    conn.CloseAsync();
                }
            }

            return(true);
        }
示例#2
0
        public bool Handle(CreateCourseCommand request)
        {
            var model = request.Adapt <MedicalCourse>();

            using (MySqlConnection conn = _context.GetConnection())
            {
                conn.Open();
                string query = string.Format("insert into Courses(course_name, qualification) values('{0}', '{1}')",
                                             model.Name, model.Qualification);
                MySqlCommand cmd = new MySqlCommand(query, conn);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    return(false);
                }
                finally
                {
                    conn.CloseAsync();
                }
            }

            return(true);
        }