Exemple #1
0
        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);
            }
        }
        public IActionResult EntrollStudent(EnrollStudentPayload payload)
        {
            if (
                String.IsNullOrEmpty(payload.IndexNumber) ||
                String.IsNullOrEmpty(payload.FirstName) ||
                String.IsNullOrEmpty(payload.LastName) ||
                String.IsNullOrEmpty(payload.BirthDate) ||
                String.IsNullOrEmpty(payload.Studies)
                )
            {
                return(BadRequest("Wypełnij wszystkie dane"));
            }

            var context = new masterContext();
            var study   = context.Studies.Single(s => s.Name.Equals(payload.Studies));

            if (study == null)
            {
                return(BadRequest("Nie ma takich studiów"));
            }

            var enrollment = context.Enrollment
                             .Where(e => e.Semester.Equals(1))
                             .SingleOrDefault(e => e.IdStudy.Equals(study.IdStudy));

            if (enrollment == null)
            {
                enrollment = new Enrollment
                {
                    Semester  = 1,
                    IdStudy   = study.IdStudy,
                    StartDate = DateTime.Now
                };
                context.Enrollment.Add(enrollment);
                context.SaveChanges();
            }

            var student = new Student
            {
                IndexNumber  = payload.IndexNumber,
                FirstName    = payload.FirstName,
                LastName     = payload.LastName,
                BirthDate    = DateTime.Parse(payload.BirthDate),
                Role         = "student",
                IdEnrollment = enrollment.IdEnrollment
            };

            context.Student.Add(student);
            context.SaveChanges();

            return(Ok("Enrolled"));
        }
Exemple #3
0
        public void setNewScore(string winner)
        {
            TblScores oldScore = db.TblScores.FirstOrDefault(x => x.PlayerName == winner);

            if (oldScore != null)
            {
                oldScore.GamesWon++;
                try
                {
                    db.Entry(oldScore).State = EntityState.Modified;

                    _logger.LogInformation("If a player with the same name existed the corresponding record is updated instead of creating a new one");

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.LogError("Exception happened:" + ex.Message, ex);
                    throw;
                }
            }
            else
            {
                TblScores newScore = new TblScores();
                newScore.PlayerName = winner;
                newScore.GamesWon   = 1;
                try
                {
                    db.Add(newScore);
                    db.SaveChanges();
                    _logger.LogInformation("if the player name didn't existed the score is a new record.");
                }
                catch (Exception ex)
                {
                    _logger.LogError("Exception happened:" + ex.Message, ex);
                    throw;
                }
            }
            try
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE [tblrounds]");
                _logger.LogInformation("Table rounds truncated to start a new game");
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception happened:" + ex.Message, ex);
                throw;
            }
        }
 public void Create()
 {
     using (masterContext con = new masterContext()){
         Games game = new Games();
         System.Console.Write("Enter name of game: ");
         game.Name = Console.ReadLine();
         System.Console.Write("Enter amount of players: ");
         game.Players = long.Parse(Console.ReadLine());
         System.Console.Write("Enter mark of this game: ");
         game.Mark = double.Parse(Console.ReadLine());
         con.Add(game);
         if (con.SaveChanges() > 0)
         {
             Console.ForegroundColor = ConsoleColor.Green;
             System.Console.WriteLine($"{game.Name} was successfully added");
             Console.ForegroundColor = ConsoleColor.White;
         }
         else
         {
             Console.ForegroundColor = ConsoleColor.Red;
             System.Console.WriteLine("Error");
             Console.ForegroundColor = ConsoleColor.White;
         }
     }
 }
Exemple #5
0
        public bool modifyStudent(Student student)
        {
            var TmpStudent = db.Student.Where(s => s.IndexNumber == student.IndexNumber).First();

            if (TmpStudent == null)
            {
                return(false);
            }

            TmpStudent.BirthDate = student.BirthDate;
            TmpStudent.FirstName = student.FirstName;
            TmpStudent.LastName  = student.LastName;

            db.SaveChanges();
            return(true);
        }
 public void Update()
 {
     using (masterContext con = new masterContext()){
         System.Console.Write("Enter Id: ");
         int gameId = int.Parse(Console.ReadLine());
         var game   = con.Games.Find(gameId);
         if (game != null)
         {
             System.Console.WriteLine("Enter new Players amount: ");
             game.Players = long.Parse(Console.ReadLine());
             System.Console.WriteLine("Enter new game's mark: ");
             game.Mark = double.Parse(Console.ReadLine());
             if (con.SaveChanges() == 0)
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 System.Console.WriteLine("Error! Game wasn't update");
                 Console.ForegroundColor = ConsoleColor.White;
             }
             else
             {
                 Console.ForegroundColor = ConsoleColor.Green;
                 System.Console.WriteLine("Game was successfully updated");
                 Console.ForegroundColor = ConsoleColor.White;
             }
         }
     }
 }
        public IActionResult promote(PromoteStudentsPayload payload)
        {
            var context = new masterContext();
            var study   = context.Studies.Single(s => s.Name.Equals(payload.Studies));

            if (study == null)
            {
                return(BadRequest("Nie ma takich studiów"));
            }

            var oldEnrolment = context.Enrollment
                               .Where(e => e.Semester.Equals(payload.Semester))
                               .SingleOrDefault(e => e.IdStudy.Equals(study.IdStudy));

            if (oldEnrolment == null)
            {
                return(BadRequest("Nie znaleziono zapisów na podane studia"));
            }

            var newEnrolment = context.Enrollment
                               .Where(e => e.Semester.Equals(payload.Semester + 1))
                               .SingleOrDefault(e => e.IdStudy.Equals(study.IdStudy));

            if (newEnrolment == null)
            {
                var newEnrollment = new Enrollment()
                {
                    Semester  = oldEnrolment.Semester + 1,
                    IdStudy   = study.IdStudy,
                    StartDate = DateTime.Now
                };
                context.Enrollment.Add(newEnrolment);
                context.SaveChanges();
            }

            var studentsToPromote = context.Student.Where(s => s.IdEnrollment.Equals(oldEnrolment.IdEnrollment))
                                    .AsEnumerable();

            foreach (var student in studentsToPromote)
            {
                student.IdEnrollment = newEnrolment.IdEnrollment;
            }

            context.SaveChanges();

            return(Ok("All students promoted :)"));
        }
 public void Update(Project4 item)
 {
     using (masterContext db = new masterContext())
     {
         db.Project4.Update(item);
         db.SaveChanges();
     }
 }
        public IActionResult ArticleViewCountUp(int id)
        {
            Article article = _context.Article.Find(id);

            article.ViewCount += 1;
            _context.SaveChanges();
            return(Ok());
        }
Exemple #10
0
 public void Update(Employee item)
 {
     using (masterContext db = new masterContext())
     {
         db.Employee.Update(item);
         db.SaveChanges();
     }
 }
Exemple #11
0
 public void Delete(string Eid)
 {
     using (masterContext db = new masterContext())
     {
         Employee e = db.Employee.Find(Eid);
         db.Employee.Remove(e);
         db.SaveChanges();
     }
 }
 public void Delete(int pid)
 {
     using (masterContext db = new masterContext())
     {
         Project4 p = db.Project4.Find(pid);
         db.Project4.Remove(p);
         db.SaveChanges();
     }
 }
        public IActionResult DeleteStudent(string indexNumber)
        {
            var context     = new masterContext();
            var studentInDb = context.Student.Find(indexNumber);

            context.Student.Remove(studentInDb);
            context.SaveChanges();

            return(NoContent());
        }
Exemple #14
0
        public int StartNewRound(TblRounds round)
        {
            try
            {
                round.FirstPlayerMove  = "";
                round.SecondPlayerMove = "";
                round.Winner           = "";
                db.Add(round);
                db.SaveChanges();

                _logger.LogInformation("New Round create with default values.");
                return(round.RoundId);
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception happened:" + ex.Message, ex);
                throw;
            }
        }
        public IActionResult Create(Land land)
        {
            if (ModelState.IsValid)
            {
                _context.Land.Add(land);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(land));
        }
 static void Main(string[] args)
 {
     using (masterContext db = new masterContext())
     {
         Item i = new Item()
         {
             ItemName = "afhhbcd", Itemprice = 100
         };
         db.Add(i);
         db.SaveChanges();
     }
 }
        public IActionResult PutStudent(PutStudentPayload payload, string indexNumber)
        {
            var context     = new masterContext();
            var studentInDb = context.Student.Find(indexNumber);

            if (studentInDb == null)
            {
                return(NotFound());
            }

            studentInDb.FirstName = payload.FirstName ?? studentInDb.FirstName;
            studentInDb.LastName  = payload.LastName ?? studentInDb.LastName;
            studentInDb.BirthDate = payload.BirthDate ?? studentInDb.BirthDate;
            context.SaveChanges();

            return(Ok("Aktualizacja zakończona"));
        }
        public IActionResult CreateStudent(CreateStudentPayload payload)
        {
            var context = new masterContext();
            var student = new Student
            {
                BirthDate   = payload.BirthDate,
                FirstName   = payload.FirstName,
                LastName    = payload.LastName,
                Role        = payload.Role,
                IndexNumber = payload.IndexNumber,
            };

            context.Student.Add(student);
            context.SaveChanges();

            return(Ok(student));
        }
Exemple #19
0
        public async Task <ActionResult <Publisher> > PostPublisherDetails()
        {
            var publisher = new Publisher();

            publisher.PublisherName = "Bruno Sajermann";
            publisher.City          = "Poá";
            publisher.State         = "SP";
            publisher.Country       = "BRA";

            Book book1 = new Book();

            book1.Title         = "Good night Moon - 1";
            book1.PublishedDate = DateTime.Now;

            Book book2 = new Book();

            book2.Title         = "Good night Moon - 2";
            book2.PublishedDate = DateTime.Now;

            publisher.Books.Add(book1);
            publisher.Books.Add(book2);

            _context.Publishers.Add(publisher);
            _context.SaveChanges();

            var publishers = _context.Publishers
                             .Include(pub => pub.Books)
                             .ThenInclude(book => book.Sales)
                             .Include(pub => pub.Users)

                             .Where(pub => pub.PubId == publisher.PubId).FirstOrDefault();

            if (publisher == null)
            {
                return(NotFound());
            }

            return(publisher);
        }
 public void Delete()
 {
     using (masterContext con = new masterContext()){
         System.Console.Write("Enter Id: ");
         int gameId = int.Parse(Console.ReadLine());
         var game   = con.Games.Find(gameId);
         if (game != null)
         {
             con.Games.Remove(game);
             if (con.SaveChanges() == 0)
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 System.Console.WriteLine("Error! Game wasn't delete");
                 Console.ForegroundColor = ConsoleColor.White;
             }
             else
             {
                 Console.ForegroundColor = ConsoleColor.Green;
                 System.Console.WriteLine("Game was successfully delete");
                 Console.ForegroundColor = ConsoleColor.White;
             }
         }
     }
 }
Exemple #21
0
 public int Commit()
 {
     return(db.SaveChanges());
 }
Exemple #22
0
 public void Save()
 {
     context.SaveChanges();
 }
        public IActionResult Update([FromBody] Contracts item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var contractitem = _context.Contracts.FirstOrDefault(t => t.ContractId == item.ContractId);

            if (contractitem == null)
            {
                return(NotFound());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                contractitem.LoanAmount = item.LoanAmount;
                contractitem.DealerName = item.DealerName;
                if (item.LoanAmount > 0 && item.LoanAmount <= 500000)
                {
                    contractitem.ContractType = "ExpressContract";
                    _context.Contracts.Update(contractitem);
                    _context.SaveChanges();
                }
                else if (item.LoanAmount > 0)
                {
                    contractitem.ContractType = "SalesContract";
                    _context.Contracts.Update(contractitem);
                    _context.SaveChanges();
                }
                else
                {
                    var logdetails = new EventLog()
                    {
                        ContractId  = contractitem.ContractId,
                        LogMessage  = "Loan Amount is less than 0, cannot update Contract for:" + contractitem.DealerName,
                        VersionUser = "******",
                        VersionDate = DateTime.Now
                    };
                    var errorlog = _context.Add(new EventLog());
                    errorlog.CurrentValues.SetValues(logdetails);
                    _context.SaveChangesAsync();
                    return(StatusCode(417));
                }
            }
            catch (Exception ex)
            {
                var logdetails = new EventLog()
                {
                    ContractId  = contractitem.ContractId,
                    LogMessage  = ex.Message,
                    VersionUser = "******",
                    VersionDate = DateTime.Now
                };
                var errorlog = _context.Add(new EventLog());
                errorlog.CurrentValues.SetValues(logdetails);
                _context.SaveChangesAsync();
            }
            return(CreatedAtRoute("GetContract", new { id = contractitem.ContractId }, contractitem));
            // return new NoContentResult();
        }
Exemple #24
0
 public void Add(Item num)
 {
     db.Item.Add(num);
     db.SaveChanges();
 }