コード例 #1
0
        public IActionResult PromoteStudent(PromoteStudentRequest request)
        {
            PromoteStudentResponse response;

            using (var con = new SqlConnection(ConString))
                using (var com = new SqlCommand())
                {
                    com.Connection = con;
                    con.Open();
                    var tran = con.BeginTransaction();
                    com.Transaction = tran;
                    try
                    {
                        com.CommandText = "exec PromoteStudents @studies, @semester ";
                        com.Parameters.AddWithValue("studies", request.Studies);
                        com.Parameters.AddWithValue("semester", request.Semester);
                        var dr = com.ExecuteReader();

                        response = new PromoteStudentResponse()
                        {
                            Name     = request.Studies,
                            Semester = request.Semester + 1
                        };
                        return(Ok(response));
                    }catch (SqlException exc)
                    {
                        return(BadRequest("nie dziala"));
                    }
                }
        }
コード例 #2
0
        public PromoteStudentResponse PromoteStudents(PromoteStudentRequest request)
        {
            var study = _context.Studies.FirstOrDefault(s => s.Name == request.Name);

            if (study == null)
            {
                throw new Exception("There is no such study");
            }


            var idStudy = _context.Studies.FirstOrDefault(s => s.Name == request.Name).IdStudy;

            var enrollment = _context.Enrollment.FirstOrDefault(en => en.Semester == request.Semester && en.IdStudy == idStudy);

            if (enrollment == null)
            {
                throw new Exception("there are no students to promote");
            }
            var res = _context.Enrollment.Where(enr => enr.Semester == request.Semester).ToList();

            res.ForEach(e =>
            {
                e.Semester = request.Semester + 1;
            });
            var response = new PromoteStudentResponse()
            {
                Semester = request.Semester + 1,
                Name     = request.Name
            };

            _context.SaveChanges();
            return(response);
        }
コード例 #3
0
ファイル: EnrollmentsController.cs プロジェクト: vlydik/Task5
        public IActionResult PromoteStudent(PromoteStudentResponse response)
        {
            PromoteStudentResponse result = new PromoteStudentResponse();

            using (var con = new SqlConnection("[Data Source=db-mssql;Initial Catalog=s19183;Integrated Security=True]"))
            {
                using (var com = new SqlCommand())
                {
                    com.Connection = con;
                    com.Parameters.AddWithValue("Semester", response.Semester);
                    com.Parameters.AddWithValue("Studies", response.Studies);
                    com.CommandText = "SELECT * FROM Enrollment e JOIN Studies s ON e.IdStudy=s.IdStudy WHERE e.Semester = @Semester AND s.Name=@Studies; ";
                    con.Open();
                    var transaction = con.BeginTransaction();
                    com.Transaction = transaction;

                    var dr = com.ExecuteReader();
                    if (dr.Read())
                    {
                        dr.Close();
                        com.CommandText = "MyProcedure";
                        com.CommandType = System.Data.CommandType.StoredProcedure;
                        com.ExecuteNonQuery();

                        result.Studies  = response.Studies;
                        result.Semester = response.Semester + 1;
                        return(Ok(result));
                    }
                    else
                    {
                        return(BadRequest("Error"));
                    }
                }
            }
        }
コード例 #4
0
ファイル: StudentDbService.cs プロジェクト: brvchd/tut7
        public PromoteStudentResponse PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse response = null;

            using (var con = new SqlConnection("Data Source=db-mssql;Initial Catalog=s18963;Integrated Security=True"))
            {
                using (SqlCommand com = new SqlCommand())
                {
                    com.Connection = con;
                    con.Open();
                    com.CommandText = "PromoteStudent";
                    com.CommandType = System.Data.CommandType.StoredProcedure;

                    com.Parameters.AddWithValue("Name", request.Name);

                    com.Parameters.AddWithValue("Semester", request.Semester);
                    var dr = com.ExecuteReader();
                    if (dr.Read())
                    {
                        dr.Close();
                        request.Name     = dr["Name"].ToString();
                        request.Semester = (int)dr["Semester"];

                        dr = com.ExecuteReader();
                        dr.Read();
                        response          = new PromoteStudentResponse();
                        response.Name     = dr["Name"].ToString();
                        response.Semester = (int)dr["Semester"];

                        dr.Close();
                    }
                }
                return(response);
            }
        }
コード例 #5
0
        public IActionResult PromoteStudents(PromoteStudentRequest request)
        {
            _service.PromoteStudents(request);
            var response = new PromoteStudentResponse();

            return(Ok(response));
        }
コード例 #6
0
        public IActionResult PromoteStudents(PromoteStudentRequest preq)
        {
            PromoteStudentResponse pres = new PromoteStudentResponse();

            pres = _dbService.PromoteStudent(preq);
            return(Created("promote", pres));
        }
コード例 #7
0
ファイル: SqlEntityDbService.cs プロジェクト: s18486/Cw5
        public PromoteStudentResponse PromoteStudent(PromoteStudentRequest request)
        {
            var enroll = db.Studies.Join(db.Enrollment,
                                         s => s.IdStudy,
                                         en => en.IdStudy,
                                         (s, e) => new { e, s.Name, s.IdStudy })
                         .Where(t => t.Name == request.Studies && t.e.Semester == request.Semester).First();

            if (enroll != null)
            {
                var tmp = db.Enrollment.Where(e => e.IdStudy == enroll.IdStudy && e.Semester == enroll.e.Semester);
                foreach (var t in tmp)
                {
                    t.Semester = t.Semester + 1;
                }
                db.SaveChanges();
                PromoteStudentResponse response = new PromoteStudentResponse
                {
                    IdEnrollment = enroll.e.IdEnrollment,
                    Semester     = enroll.e.Semester,
                    Study        = enroll.Name,
                    StartDate    = enroll.e.StartDate
                };
                return(response);
            }
            else
            {
                return(null);
            }
        }
コード例 #8
0
ファイル: EfStudentDbService.cs プロジェクト: s18687/cw10
        public PromoteStudentResponse PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse response = new PromoteStudentResponse();
            List <Student>         stud     = new List <Student>();

            var studies = _dbContext.Studies
                          .Where(s => s.Name.Equals(request.Studies))
                          .Single();
            var OldEnrollment = _dbContext.Enrollment
                                .Where(e => e.IdStudy == studies.IdStudy && e.Semester == request.Semester)
                                .Single();
            var enrollment = _dbContext.Enrollment
                             .Where(e => e.IdStudy == studies.IdStudy && e.Semester == request.Semester + 1)
                             .SingleOrDefault();
            int idEnrollment;

            if (enrollment == null)
            {
                idEnrollment = _dbContext.Enrollment.Count() + 1;
                var e = new Enrollment
                {
                    IdEnrollment = idEnrollment,
                    Semester     = request.Semester + 1,
                    IdStudy      = studies.IdStudy,
                    StartDate    = DateTime.Now
                };

                _dbContext.Enrollment.Add(e);
                _dbContext.SaveChanges();
            }
            else
            {
                idEnrollment = enrollment.IdEnrollment;
            }

            var students = _dbContext.Student
                           .Where(s => s.IdEnrollment == OldEnrollment.IdEnrollment)
                           .ToList();

            foreach (Student s in students)
            {
                s.IdEnrollment = idEnrollment;
                _dbContext.SaveChanges();
                var s1 = new Student
                {
                    IndexNumber  = s.IndexNumber,
                    FirstName    = s.FirstName,
                    LastName     = s.LastName,
                    BirthDate    = s.BirthDate,
                    IdEnrollment = idEnrollment,
                };
                stud.Add(s1);
            }

            response.students = stud;


            return(response);
        }
コード例 #9
0
        public PromoteStudentResponse PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse response = new PromoteStudentResponse();

            using (SqlConnection connectionSql = new SqlConnection(ConString))
                using (var sqlCommand = new SqlCommand("PromoteStudents", connectionSql))
                {
                    sqlCommand.CommandType = CommandType.StoredProcedure;

                    sqlCommand.Parameters.AddWithValue("@Studies", request.Studies);
                    sqlCommand.Parameters.AddWithValue("@semester", request.Semester);

                    connectionSql.Open();
                    sqlCommand.ExecuteNonQuery();
                    connectionSql.Close();
                    response.dtoResponse = "Done";

                    SqlCommand command = new SqlCommand();
                    command.Connection = connectionSql;
                    connectionSql.Open();

                    int newSemester = request.Semester + 1;

                    command.CommandText = "SELECT IdStudy FROM Studies where Name=@name";
                    command.Parameters.AddWithValue("name", request.Studies);

                    var idStudies = command.ExecuteReader();

                    if (!idStudies.Read())
                    {
                        response.dtoResponse = "Podanych studia nie istnieją";
                        return(response);
                    }

                    int idstudies = (int)idStudies["IdStudy"];
                    idStudies.Close();

                    Enrollment enrollment = new Enrollment();

                    command.CommandText = "SELECT idEnrollment,idStudy,Semester,StartDate FROM Enrollment WHERE idStudy=@idStudy AND Semester=@Semester";
                    command.Parameters.AddWithValue("idStudy", idstudies);
                    command.Parameters.AddWithValue("Semester", newSemester);

                    var newEnrollSemester = command.ExecuteReader();

                    if (newEnrollSemester.Read())
                    {
                        enrollment.IdEnrollment = (int)newEnrollSemester["IdEnrollment"];
                        enrollment.IdStudy      = (int)newEnrollSemester["IdStudy"];
                        enrollment.Semester     = (int)newEnrollSemester["Semester"];
                        enrollment.StartDate    = (String)newEnrollSemester["StartDate"];
                    }

                    newEnrollSemester.Close();
                    response.enrollment = enrollment;

                    return(response);
                }
        }
コード例 #10
0
        public PromoteStudentResponse PromoteStudent(PromoteStudentRequest promotion)
        {
            using (var connection = new SqlConnection("Data Source=db-mssql;Initial Catalog=s18589;Integrated Security=true"))
                using (var command = new SqlCommand())
                {
                    connection.Open();
                    command.Connection = connection;
                    var transaction = connection.BeginTransaction();
                    command.Transaction = transaction;
                    Console.WriteLine(promotion.Studies);
                    command.Parameters.AddWithValue("name", promotion.Studies);
                    command.Parameters.AddWithValue("semester", promotion.Semester);

                    command.CommandText = "select * from enrollment inner join studies on enrollment.idstudy = studies.idstudy where studies.name = @name and enrollment.semester = @semester";

                    var dr = command.ExecuteReader();
                    command.Parameters.Clear();
                    if (!dr.HasRows)
                    {
                        dr.Close();
                        transaction.Rollback();
                        throw new Exception("query failed");
                    }
                    dr.Close();

                    command.Parameters.AddWithValue("name", promotion.Studies);
                    command.Parameters.AddWithValue("semester", promotion.Semester);
                    command.CommandText = "exec promotion @name,@semester";
                    command.ExecuteNonQuery();

                    command.CommandText = "select * from enrollment inner join studies on enrollment.idstudy = studies.idstudy where studies.name = @name and enrollment.semester = @semester+1";

                    dr = command.ExecuteReader();


                    if (!dr.HasRows)
                    {
                        dr.Close();
                        transaction.Rollback();
                        throw new Exception("no promoted students");
                    }

                    dr.Read();
                    PromoteStudentResponse response = new PromoteStudentResponse
                    {
                        IdEnrollment = int.Parse(dr["IdEnrollment"].ToString()),
                        Semester     = int.Parse(dr["Semester"].ToString()),
                        IdStudy      = int.Parse(dr["IdStudy"].ToString()),
                        StartDate    = DateTime.Parse(dr["StartDate"].ToString())
                    };

                    dr.Close();
                    transaction.Commit();

                    return(response);
                }
        }
コード例 #11
0
ファイル: ReceptsController.cs プロジェクト: s18943/Kolokwium
        public IActionResult AddRecept(ReceptRequest request)
        {
            PromoteStudentResponse result = _service.AddRecept(request);

            if (result != null)
            {
                return(Ok(result));
            }
            return(BadRequest(400));
        }
コード例 #12
0
        public IActionResult PromoteStudents(PromoteStudentRequest promoteStudentRequest)
        {
            PromoteStudentResponse promoteStudentResponse = _db.PromoteStudents(promoteStudentRequest);

            if (promoteStudentResponse == null)
            {
                return(NotFound());
            }
            return(this.StatusCode(201, promoteStudentResponse));
        }
コード例 #13
0
        public async Task <IActionResult> PromoteStudents(PromoteStudentRequest promoteStudentRequest)
        {
            PromoteStudentResponse promoteStudentResponse = await _db.PromoteStudentsAsync(promoteStudentRequest);

            if (promoteStudentResponse == null)
            {
                return(NotFound());
            }
            return(this.StatusCode(201, promoteStudentResponse));
        }
コード例 #14
0
        public IActionResult PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse promoteResp = dbService.PromoteStudents(request);

            if (promoteResp == null)
            {
                return(BadRequest());
            }

            return(this.StatusCode(201, promoteResp));
        }
コード例 #15
0
        public IActionResult PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse response = null;

            try
            {
                response = studentDbService.PromoteStudents(request);
            }
            catch (SqlException ex)
            {}
            return(Created("PromoteStudent", response));
        }
コード例 #16
0
        public PromoteStudentResponse PromoteStudents(PromoteStudentRequest request)
        {
            var          response = new PromoteStudentResponse();
            DateTime     date     = DateTime.Today;
            int          success;
            const string ConString = "Data Source=db-mssql;Initial Catalog=s18985;Integrated Security=True";

            using (var con = new SqlConnection(ConString))
                using (var com = new SqlCommand())
                {
                    com.Connection = con;

                    con.Open();
                    var tran = con.BeginTransaction();

                    com.CommandText = "execute PromoteStudent @study, @semester";
                    com.Parameters.AddWithValue("study", request.Studies);
                    com.Parameters.AddWithValue("semester", request.Semester);
                    com.Transaction = tran;
                    success         = com.ExecuteNonQuery();

                    var nextSemestr = request.Semester + 1;
                    com.CommandText = "select IdEnrollment from enrollment where semester = @nextSemester and idstudy = (select idstudy from studies where name = @study)";
                    com.Parameters.AddWithValue("nextSemester", nextSemestr);
                    com.Transaction = tran;
                    var dr = com.ExecuteScalar();

                    response.IdEnrollment = (int)dr;

                    com.CommandText = "select StartDate from enrollment where semester = @nextSemester and idstudy = (select idstudy from studies where name = @study)";
                    com.Transaction = tran;
                    dr = com.ExecuteScalar();

                    response.StartDate = (DateTime)dr;

                    tran.Commit();

                    response.Studies  = request.Studies;
                    response.Semester = request.Semester + 1;


                    if (success > 0)
                    {
                        return(response);

                        return(response);
                    }
                    else
                    {
                        return(null);
                    }
                }
        }
コード例 #17
0
        public async Task <IActionResult> PromoteStudents(PromoteStudentRequest request)
        {
            await _dbService.PromoteStudents(request);

            var response = new PromoteStudentResponse()
            {
                Semester    = Convert.ToInt32(request.Semester) + 1,
                StudiesName = request.StudiesName
            };

            return(Ok(response));
        }
コード例 #18
0
 public PromoteStudentResponse PromoteStudents(PromoteStudentRequest promoteStudentRequest)
 {
     using (var conn = new SqlConnection(connString))
     {
         conn.Open();
         var transaction = conn.BeginTransaction();
         using (var comm = new SqlCommand())
         {
             comm.CommandText = @"select * from 
                                     Enrollment a inner join Studies b
                                     On a.IdStudy=b.IdStudy 
                                     And b.Name=@Name                                            
                                     AND a.Semester=@Semester";
             comm.Parameters.AddWithValue("@Name", promoteStudentRequest.Studies);
             comm.Parameters.AddWithValue("@Semester", promoteStudentRequest.Semester);
             comm.Connection  = conn;
             comm.Transaction = transaction;
             using (var reader = comm.ExecuteReader())
             {
                 if (!reader.Read())
                 {
                     reader.Close();
                     transaction.Rollback();
                     return(null);
                 }
             }
         }
         using (var comm1 = new SqlCommand("promoteStudent", conn))
         {
             comm1.CommandType = System.Data.CommandType.StoredProcedure;
             comm1.CommandText = "PromoteStudent";
             comm1.Parameters.AddWithValue("@studiesGiven", promoteStudentRequest.Studies);
             comm1.Parameters.AddWithValue("@semesterGiven", promoteStudentRequest.Semester);
             comm1.Connection  = conn;
             comm1.Transaction = transaction;
             using (var reader = comm1.ExecuteReader())
             {
                 reader.Read();
                 PromoteStudentResponse promoteStudentResponse = new PromoteStudentResponse
                 {
                     IdEnrollment = int.Parse(reader["IdEnrollment"].ToString()),
                     Semester     = int.Parse(reader["Semester"].ToString()),
                     IdStudy      = int.Parse(reader["IdStudy"].ToString()),
                     StartDate    = DateTime.Parse(reader["StartDate"].ToString())
                 };
                 reader.Close();
                 transaction.Commit();
                 return(promoteStudentResponse);
             }
         }
     }
 }
コード例 #19
0
        public PromoteStudentResponse PromoteStudents(int semester, string studies)
        {
            PromoteStudentResponse promote = new PromoteStudentResponse();

            promote.Studies  = studies;
            promote.Semester = semester;
            using (var con = new SqlConnection(sqlConnection))
                using (var com = new SqlCommand())
                {
                    com.Connection = con;
                    con.Open();
                    var tran = con.BeginTransaction();
                    com.Transaction = tran;

                    //Czy wpisy sa poprawne
                    com.CommandText = "select * from Enrollment INNER JOIN Studies ON Enrollment.IdStudy=Studies.IdStudy where Enrollment.Semester=@semester OR Studies.Name=@name";
                    com.Parameters.AddWithValue("semester", semester);
                    com.Parameters.AddWithValue("name", studies);


                    var dr = com.ExecuteReader();
                    if (!dr.Read())
                    {
                        promote.Info = "400 Wpisz prawidlowa nazwe studiow";
                        dr.Close();
                        tran.Rollback();
                    }
                    int idStudy     = (int)dr["IdStudy"];
                    int nrSemester  = (int)dr["semester"];
                    int newSemester = nrSemester + 1;
                    dr.Close();

                    //Jezeli wpisy poprawne, aktualizuj semestr studentow
                    try
                    {
                        com.CommandText = "update Enrollment set Semester=@newSemester where IdStudy=@idStudy and Semester=@nrSemester";
                        com.Parameters.AddWithValue("newSemester", newSemester);
                        com.Parameters.AddWithValue("nrSemester", nrSemester);
                        com.Parameters.AddWithValue("idStudy", idStudy);
                        com.ExecuteNonQuery();
                        tran.Commit();
                        promote.Info = "201 Semestr zmieniony";
                    }
                    catch (SqlException e)
                    {
                        promote.Info = "400 Blad podczad aktualizacji semestru" + e;
                        tran.Rollback();
                    }
                }

            return(promote);
        }
コード例 #20
0
ファイル: EnrollmentsController.cs プロジェクト: miniluxy/cw7
        public IActionResult PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse response = _service.PromoteStudent(request);

            if (response == null)
            {
                return(StatusCode(401, BadRequest("blad 401")));
            }
            else
            {
                return(StatusCode(201, response));
            }
        }
コード例 #21
0
        public IActionResult PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse response = dbService.PromoteStudent(request);

            if (response == null)
            {
                return(NotFound("Wrong data was passed"));
            }
            else
            {
                return(StatusCode(201, response));
            }
        }
        public async Task <IActionResult> PromoteStudents(PromoteStudentRequest req)
        {
            PromoteStudentResponse resp = await _service.PromoteStudents(req);

            if (resp == null)
            {
                return(BadRequest());
            }
            else
            {
                return(this.StatusCode(201, resp));
            }
        }
コード例 #23
0
        public IActionResult PromoteStudents(PromoteStudentRequest request)
        {
            PromoteStudentResponse response = null;

            try
            {
                response = _studentDbService.PromoteStudents(request);
            }
            catch (SqlException sqlex)
            {
                WriteLine(sqlex.Message);
            }
            return(Created("PromoteStudent", response));
        }
コード例 #24
0
        public PromoteStudentResponse PromoteStudents(int semester, string studies)
        {
            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                int idStudy = _dbContext.Studies
                              .Where(st => st.Name == studies)
                              .Select(st => st.IdStudy).SingleOrDefault();

                PartialModels.Enrollment enrollment = _dbContext.Enrollment.FirstOrDefault(e => e.IdStudy == idStudy && e.Semester == semester);

                if (enrollment == null)
                {
                    return(null);
                }

                int oldIdEnrollment = enrollment.IdEnrollment;
                enrollment = _dbContext.Enrollment.FirstOrDefault(e => e.IdStudy == idStudy && e.Semester == semester + 1);

                if (enrollment == null)
                {
                    int maxId = _dbContext.Enrollment.Max(e => e.IdEnrollment);
                    enrollment = new PartialModels.Enrollment();
                    enrollment.IdEnrollment = maxId + 1;
                    enrollment.Semester     = semester + 1;
                    enrollment.IdStudy      = idStudy;
                    enrollment.StartDate    = DateTime.Now;
                    _dbContext.Enrollment.Add(enrollment);
                    _dbContext.SaveChanges();
                }

                var students = _dbContext.Student.Where(s => s.IdEnrollment == oldIdEnrollment).ToList();

                foreach (Student student in students)
                {
                    student.IdEnrollment = enrollment.IdEnrollment;
                }

                _dbContext.SaveChanges();
                transaction.Commit();
                var response = new PromoteStudentResponse()
                {
                    Study       = studies,
                    NewIdStudy  = enrollment.IdStudy,
                    NewSemester = enrollment.Semester
                };

                return(response);
            }
        }
コード例 #25
0
        public PromoteStudentResponse PromoteStudents(PromoteStudentRequest request)
        {
            var response = new PromoteStudentResponse();

            using var con = new SqlConnection(SetConnection.GetConnection());
            using var com = new SqlCommand();

            con.Open();
            com.Connection = con;
            var transaction = con.BeginTransaction();

            com.Transaction = transaction;

            com.CommandText = "SELECT enr.IdEnrollment from Enrollment enr INNER JOIN Studies st on enr.IdStudy = st.IdStudy WHERE st.Name = @Name and enr.Semester = @Semester";
            com.Parameters.AddWithValue("Name", request.Name);
            com.Parameters.AddWithValue("Semester", request.Semester);

            var dr = com.ExecuteReader();

            if (!dr.Read())
            {
                dr.Close();
                throw new  Exception("Nie znalezono semestru i/lub studiów");
            }
            else
            {
                dr.Close();


                using (SqlConnection conn = new SqlConnection(SetConnection.GetConnection()))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("PromoteStudents", conn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add(new SqlParameter("@Name", request.Name));
                    cmd.Parameters.Add(new SqlParameter("@Semester", request.Semester));
                    cmd.ExecuteReader();
                    conn.Close();
                }
                response.Semester    = request.Semester + 1;
                response.StartDate   = DateTime.Now.ToString("dd.MM.yyyy");
                response.StudiesName = request.Name;

                transaction.Commit();
            }

            return(response);
        }
コード例 #26
0
ファイル: EfDbService.cs プロジェクト: s16534/CW10
        public IEnumerable <PromoteStudentResponse> PromoteStudent(PromoteStudentRequest promoteStudentRequest)
        {
            var responsesList = new List <PromoteStudentResponse>();

            //SELECTY
            //Kierunek o podanym skrócie
            var study = _context.Studies.Single(s => s.Name == promoteStudentRequest.Name);

            //Wpis dla podanego kierunku na konkretny semstr
            var enrollment = _context.Enrollment.Single(e => e.Semester == promoteStudentRequest.Semester && e.IdStudy == study.IdStudy);

            //Wpis dla podanego kierunku na następny semestr
            var newEnrollment = _context.Enrollment.Single(e => e.Semester == promoteStudentRequest.Semester + 1 && e.IdStudy == study.IdStudy);

            //Ostatnie ID + 1
            var newIdEnrollment = _context.Enrollment.Max(e => e.IdEnrollment) + 1;


            if (newEnrollment == null)
            {
                _context.Enrollment.Add(new Enrollment
                {
                    IdEnrollment = newIdEnrollment,
                    Semester     = promoteStudentRequest.Semester + 1,
                    IdStudy      = study.IdStudy,
                    StartDate    = DateTime.Now
                });
                newEnrollment = _context.Enrollment.Single(e => e.Semester == promoteStudentRequest.Semester + 1 && e.IdStudy == study.IdStudy);
            }
            var students = _context.Student.Where(student => student.IdEnrollment == enrollment.IdEnrollment).ToList();

            foreach (var student in students)
            {
                student.IdEnrollment = newEnrollment.IdEnrollment;
            }

            var promoteStudentResponse = new PromoteStudentResponse
            {
                IdEnrollment = newEnrollment.IdEnrollment,
                Semester     = promoteStudentRequest.Semester + 1,
                IdStudy      = study.IdStudy,
                StartDate    = DateTime.Now
            };

            responsesList.Add(promoteStudentResponse);
            return(responsesList);
        }
コード例 #27
0
 public PromoteStudentResponse PromoteStudent(PromoteStudentRequest request)
 {
     using (SqlConnection con = new SqlConnection(ConString))
         using (SqlCommand com = new SqlCommand())
         {
             try
             {
                 com.Connection  = con;
                 com.CommandText = "select * from Enrollment inner join Studies on Enrollment.IdStudy=Study.IdStudy where Name=@StudyName and Semester=@Semester";
                 com.Parameters.AddWithValue("@StudiesName", request.Studies);
                 com.Parameters.AddWithValue("@Semester", request.Semester);
                 con.Open();
                 var dr = com.ExecuteReader();
                 if (!dr.Read())
                 {
                     return(null);
                 }
                 dr.Close();
                 com.Parameters.Clear();
                 com.CommandText = "PromoteStudents";
                 com.CommandType = CommandType.StoredProcedure;
                 com.Parameters.AddWithValue("@Studies", request.Studies);
                 com.Parameters.AddWithValue("@Semester", request.Semester);
                 dr = com.ExecuteReader();
                 if (dr.Read())
                 {
                     PromoteStudentResponse response = new PromoteStudentResponse();
                     response.IdEnrollment = int.Parse(dr["IdEnrollment"].ToString());
                     response.Semester     = int.Parse(dr["Semester"].ToString());
                     response.Studies      = dr["Name"].ToString();
                     response.StartDate    = DateTime.Parse(dr["StartDate"].ToString());
                     dr.Close();
                     return(response);
                 }
                 else
                 {
                     return(null);
                 }
             }
             catch (SqlException ex)
             {
                 return(null);
             }
         }
 }
コード例 #28
0
ファイル: SqlServerDbService.cs プロジェクト: s18793/wyklad4
        public PromoteStudentResponse PromoteStudent(PromoteStudentRequest psrequest)
        {
            using (SqlConnection con = new SqlConnection("Data Source = db - mssql; Initial Catalog = s18793; Integrated Security = True"))
                using (SqlCommand com = new SqlCommand())
                    using (var tran = con.BeginTransaction())
                    {
                        PromoteStudentResponse response = new PromoteStudentResponse();
                        con.Open();
                        com.Connection  = con;
                        com.Transaction = tran;
                        try
                        {
                            com.CommandText = "exec PromoteStudents @name, @semester";
                            com.Parameters.AddWithValue("semester", psrequest.Semester);
                            com.Parameters.AddWithValue("name", psrequest.Name);
                            com.ExecuteNonQuery();


                            com.CommandText = "SELECT * FROM Enrollment e INNER JOIN Studies stud ON stud.idstudy = e.idstudy WHERE e.semester = Semest AND stud.name = stName";
                            com.Parameters.AddWithValue("stName", psrequest.Name);
                            com.Parameters.AddWithValue("Semest", psrequest.Semester);
                            var dr = com.ExecuteReader();


                            if (!dr.Read())
                            {
                                dr.Close();
                                tran.Rollback();
                            }
                            else
                            {
                                response.IdEnrollment = (int)dr["IdEnrollment"];
                                response.IdStudy      = dr["IdStudy"].ToString();
                                response.Semester     = dr["Semester"].ToString();
                                response.StartDate    = (DateTime)dr["StartDate"];
                            }
                        }
                        catch (SqlException e)
                        {
                            tran.Rollback();
                        }

                        return(response);
                    }
        }
コード例 #29
0
        public void PromoteStudents(PromoteStudentRequest request)
        {
            string connstring =
                "Data Source=10.1.1.36,1433;Initial Catalog=s18588;User ID=apbds18588;Password=admin";
            var response = new PromoteStudentResponse();
            var cl       = new HttpClient();

            cl.BaseAddress = new Uri("http://*****:*****@Studies and Semester = @Semester";
                    com.Parameters.AddWithValue("Studies", IdStudies);
                    com.Parameters.AddWithValue("Semester", request.Semester);
                    var dr = com.ExecuteReader();
                    com.Parameters.Clear();

                    if (dr.Read())
                    {
                        dr.Close();
                        com.CommandText = "update Enrollment set Semester = @SemesterNo where IdStudy = @Studies and Semester = @Semester";
                        com.Parameters.AddWithValue("Studies", IdStudies);
                        com.Parameters.AddWithValue("Semester", (int)request.Semester);
                        com.Parameters.AddWithValue("SemesterNo", request.Semester + 1);
                        com.ExecuteNonQuery();
                        response.Studies  = request.Studies;
                        response.Semester = request.Semester + 1;
                        Console.WriteLine("Ok");
                    }
                }
        }
コード例 #30
0
        public IActionResult PromoteStudents(PromoteStudentsRequest request)
        {
            int changedEnrollment      = 0;
            var promoteStudnetResponse = new PromoteStudentResponse();

            using (var connection = new SqlConnection(
                       "Data Source=db-mssql.pjwstk.edu.pl;Initial Catalog=s18711;Integrated Security=True"))
                using (var command = new SqlCommand("dbo.Promote", connection))
                    using (var command2 = new SqlCommand())
                    {
                        command2.Connection = connection;

                        command.CommandType = CommandType.StoredProcedure;

                        command.Parameters.Add("@StudiesName", SqlDbType.VarChar, 100);
                        command.Parameters.Add("@Semester", SqlDbType.Int);
                        command.Parameters.Add("@myOut", SqlDbType.Int).Direction = ParameterDirection.Output;

                        command.Parameters["@StudiesName"].Value = request.Studies;
                        command.Parameters["@Semester"].Value    = request.Semester;

                        connection.Open();
                        command.ExecuteNonQuery();

                        changedEnrollment = Convert.ToInt32(command.Parameters["@myOut"].Value);

                        command2.CommandText = "SELECT * FROM Enrollment WHERE IdEnrollment = @IdE";
                        command2.Parameters.AddWithValue("IdE", changedEnrollment);

                        var dataReader = command2.ExecuteReader();

                        if (dataReader.Read())
                        {
                            promoteStudnetResponse.IdEnrollment = int.Parse(dataReader["IdEnrollment"].ToString());
                            promoteStudnetResponse.IdStudies    = int.Parse(dataReader["IdStudy"].ToString());
                            promoteStudnetResponse.Semester     = int.Parse(dataReader["Semester"].ToString());
                        }
                    }



            return(CreatedAtAction("PromoteStudents", promoteStudnetResponse));
        }