Exemplo n.º 1
0
        public HttpResponseMessage AddStudent(DataStudents data)
        {
            string SName        = data.SName;
            string Email        = data.Email;
            string MobileNumber = data.MobileNumber;
            string RollNumber   = data.RollNumber;
            string SPassword    = data.SPassword;
            int    BatchID      = data.BatchID;
            int    ProgrammeID  = data.ProgrammeID;


            var db = DbUtils.GetDBConnection();

            db.Connection.Open();

            using (TransactionScope scope = new TransactionScope())
            {
                var query = db.Query("Student").InsertGetId <int>(new
                {
                    SName        = SName,
                    Email        = Email,
                    MobileNumber = MobileNumber,
                    RollNumber   = RollNumber,
                    SPassword    = SPassword,
                    BatchID      = BatchID,
                    ProgrammeID  = ProgrammeID,
                    CandidateID  = 2
                });


                scope.Complete();  // if record is entered successfully , transaction will be committed


                db.Connection.Close();
                return(Request.CreateResponse(HttpStatusCode.OK, query));
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage DeleteStudent(DataStudents data)
        {
            int id = data.StudentID;

            var db = DbUtils.GetDBConnection();

            db.Connection.Open();

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    db.Query("Student").Where("StudentID", id).Delete();
                    scope.Complete();
                    db.Connection.Close();
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                catch (Exception ex)
                {
                    scope.Dispose();
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }