예제 #1
0
        public m_cls_Student_D Save(m_cls_Student_D oStudent)
        {
            //throw new System.NotImplementedException();
            _oStudent = new m_cls_Student_D();

            try{
                int operationType = Convert.ToInt32(oStudent.StudentId == 0 ? OperationType.Insert : OperationType.Update);

                using (IDbConnection con = new SqlConnection(Global.ConnectionString))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    var oStudents = con.Query <m_cls_Student_D>("sp_Student",
                                                                this.SetParameters(oStudent, operationType),
                                                                commandType: CommandType.StoredProcedure
                                                                );

                    if (oStudents != null && oStudents.Count() > 0)
                    {
                        _oStudent = oStudents.FirstOrDefault();
                    }
                }
            }
            catch (Exception ex)
            {
                _oStudent.Message = ex.Message;
            }

            return(_oStudent);
        }
예제 #2
0
 public m_cls_Student_D Post([FromBody] m_cls_Student_D oStudent)
 {
     if (ModelState.IsValid)
     {
         return(_oStudentService.Save(oStudent));
     }
     return(null);
 }
예제 #3
0
        private DynamicParameters SetParameters(m_cls_Student_D oStudent, int operationType)
        {
            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("@StudentId", oStudent.StudentId);
            parameters.Add("@StudentName", oStudent.StudentName);
            parameters.Add("@Roll", oStudent.Roll);
            parameters.Add("@OperationType", operationType);

            return(parameters);
        }
        public object Save(m_cls_Student_D oStudent, m_cls_Teacher_D oTeacher)
        {
            //throw new System.NotImplementedException();
            dynamic obj = new ExpandoObject();

            try
            {
                int operationType = 0;

                using (IDbConnection con = new SqlConnection(Global.ConnectionString))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    string query = @"EXEC sp_Student @StudentId, @StudentName, @Roll, @OperationType; " +
                                   "EXEC sp_Teacher @TeacherId, @FullName, @SubjectName";

                    using (var multi = con.QueryMultiple(query, new {
                        oStudent.StudentId,
                        oStudent.StudentName,
                        oStudent.Roll,
                        operationType,
                        oTeacher.TeacherId,
                        oTeacher.FullName,
                        oTeacher.SubjectName
                    }))
                    {
                        obj.Student = multi.Read <m_cls_Student_D>().Single();
                        obj.Teacher = multi.Read <m_cls_Teacher_D>().Single();
                    }
                }
            }
            catch (Exception ex)
            {
                obj.Message = ex.Message;
            }

            return(obj);
        }
예제 #5
0
        public m_cls_Student_D Get(int studentId)
        {
            //throw new System.NotImplementedException();
            _oStudent = new m_cls_Student_D();
            using (IDbConnection con = new SqlConnection(Global.ConnectionString))
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }

                string query = "SELECT * FROM tbl_Student_D WHERE studentId = @studentId";

                var oStudent = con.Query <m_cls_Student_D>(query, new { studentId = studentId }).ToList();

                if (oStudent != null && oStudent.Count() > 0)
                {
                    _oStudent = oStudent.SingleOrDefault();
                }

                return(_oStudent);
            }
        }
예제 #6
0
        public string Delete(int studentId)
        {
            //throw new System.NotImplementedException();
            string message = "";

            try
            {
                _oStudent = new m_cls_Student_D()
                {
                    StudentId = studentId
                };

                using (IDbConnection con = new SqlConnection(Global.ConnectionString))
                {
                    if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }

                    var oStudents = con.Query <m_cls_Student_D>("sp_Student",
                                                                this.SetParameters(_oStudent, (int)OperationType.Delete),
                                                                commandType: CommandType.StoredProcedure
                                                                );

                    if (oStudents != null && oStudents.Count() > 0)
                    {
                        _oStudent = oStudents.FirstOrDefault();
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            return(message);
        }