Exemplo n.º 1
0
 public static void InitDb()
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         ctx.Database.Initialize(true);
     }
 }
Exemplo n.º 2
0
 public static List <Guest> GetAllUnsignedGuests()
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Guests.Where(g => g.DateLeft == null).ToList());
     }
 }
Exemplo n.º 3
0
 public static University GetUniversityByName(string uniName)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Universities.FirstOrDefault(u => u.Name == uniName));
     }
 }
Exemplo n.º 4
0
 public static List <Room> GetRooms()
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Rooms.ToList());
     }
 }
Exemplo n.º 5
0
 public static decimal GetTotalTakingsForCampus(int campusId)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Campuses.FirstOrDefault(c => c.Id == campusId).Students.Sum(s => s.Obligations));
     }
 }
Exemplo n.º 6
0
 public static List <Room> GetRoomsByCampus(Campus campus)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Rooms.Include("Students").Where(r => r.CampusId == campus.Id).OrderBy(r => r.Number).ToList());
     }
 }
Exemplo n.º 7
0
 public static Room getRoomInCampusByNumber(string roomNumber, int campusId)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Campuses.FirstOrDefault(c => c.Id == campusId).Rooms.FirstOrDefault(r => r.Number == roomNumber));
     }
 }
Exemplo n.º 8
0
 public static Campus GetCampus(string campusNumber)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Campuses.FirstOrDefault(c => c.Number.Equals(campusNumber)));
     }
 }
Exemplo n.º 9
0
 public static int GetStudentsInRoom(string roomNumber)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Students.Where(s => s.Room.Number == roomNumber).Count());
     }
 }
Exemplo n.º 10
0
 public static IEnumerable <University> GetUniversities()
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Universities.ToList());
     }
 }
Exemplo n.º 11
0
 public static Student GetStudentById(int studentId)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Students.FirstOrDefault(st => st.Id == studentId));
     }
 }
Exemplo n.º 12
0
 public static List <Town> GetTowns()
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Towns.ToList());
     }
 }
Exemplo n.º 13
0
 public static List <Student> GetStudents()
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Students.Include("Room").Include("Guests").Include("Town").Include("University").Include("Campus").ToList());
     }
 }
Exemplo n.º 14
0
 public static Student GetStudentByRoomAndName(string roomNumber, string student)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Students.FirstOrDefault(s => s.Room.Number == roomNumber && s.FullName == student));
     }
 }
Exemplo n.º 15
0
 public static List <Guest> GetAllUnsignedGuestsForCampus(int id)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Guests.Include("StudentVisited").Include("Town").Include("StudentVisited.Room").Where(g => g.CampusId == id && g.DateLeft == null).ToList());
     }
 }
Exemplo n.º 16
0
 public static string GetTotalObligationsByRoom(string roomNumber)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Rooms.FirstOrDefault(r => r.Number == roomNumber).Students.Sum(s => s.Obligations).ToString());
     }
 }
Exemplo n.º 17
0
 public static void AddGuest(Guest guest)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         ctx.Guests.Add(guest);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 18
0
 public static void AddStudent(Student student)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         ctx.Students.Add(student);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 19
0
 public static void ReleaseGuest(Guest guest)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         ctx.Guests.FirstOrDefault(g => g.Id == guest.Id).DateLeft = DateTime.Now;
         ctx.SaveChanges();
     }
 }
Exemplo n.º 20
0
 public static List <Student> GetStudentsByCampus(int campusId)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         return(ctx.Students.Include("Room").Include("Guests").
                Include("Town").Include("University")
                .Include("Campus").Where(s => s.CampusId == campusId).ToList());
     }
 }
Exemplo n.º 21
0
 public static void PayObligationsById(int studentId)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         var student = ctx.Students.FirstOrDefault(st => st.Id == studentId);
         student.Obligations      = 0;
         ctx.Entry(student).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Exemplo n.º 22
0
 public static void AddRoomToCampus(Room room)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         if (!ctx.Rooms.Any(r => r.Number == room.Number && r.CampusId == room.CampusId))
         {
             ctx.Rooms.Add(room);
             ctx.SaveChanges();
         }
         else
         {
             throw new InvalidOperationException("Cannot add already existing room to campus.");
         }
     }
 }
Exemplo n.º 23
0
 public static Town GetTownByName(string townName)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         var town = ctx.Towns.FirstOrDefault(t => t.Name == townName);
         if (town == null)
         {
             var newTown = new Town
             {
                 Name = townName
             };
             ctx.Towns.Add(newTown);
             ctx.SaveChanges();
             return(newTown);
         }
         return(town);
     }
 }
Exemplo n.º 24
0
 public static void AddCampus(Campus camp)
 {
     using (CampusSystemContext ctx = new CampusSystemContext())
     {
         for (int i = 1; i < 7; i++)
         {
             for (int j = 0; j < 10; j++)
             {
                 string roomFloor = i.ToString();
                 string roomNum   = j.ToString();
                 if (roomNum.Length == 1)
                 {
                     roomNum = $"0{roomNum}";
                 }
                 camp.Rooms.Add(new Room
                 {
                     Number = $"{roomFloor}{roomNum}"
                 });
             }
         }
         ctx.Campuses.Add(camp);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            //TODO: CREATE TRIGGER FOR ADDING ROOM IN CAMPUS

            CampusSystemContext ctx = new CampusSystemContext();

            ctx.Database.Initialize(true);
            //InitialFill.FillIndividualData(ctx);
            //System.Console.WriteLine(ctx.Rooms.Count());

            #region Add rooms in campus
            //ctx.Campuses.Add(new Campus
            //{
            //    Number = "3",
            //    UniversityId = 2
            //});
            //ctx.SaveChanges();

            //ctx.Campuses.Add(new Campus
            //{
            //    Number = "2",
            //    UniversityId = 1
            //}); ctx.SaveChanges();
            //ctx.Rooms.Add(new Room
            //{
            //    Number = "302",
            //    CampusId = 2
            //});
            //ctx.Rooms.Add(new Room
            //{
            //    Number = "403",
            //    CampusId = 2
            //});
            //ctx.Rooms.Add(new Room
            //{
            //    Number = "304",
            //    CampusId = 2
            //});
            //ctx.Rooms.Add(new Room
            //{
            //    Number = "205",
            //    CampusId = 2
            //});
            //ctx.SaveChanges();
            #endregion

            #region Get Obligations For Campus
            //var name = "Sofia University";
            //var obligationsByCampus = ctx.Campuses.Where(c => c.University.Name == name)
            //    .Sum(c => c.Rooms.Sum(r => r.Students.Sum(s => s.Obligations)));
            //    System.Console.WriteLine(obligationsByCampus);
            #endregion

            #region Get Obligations For Room
            //var number = "101";
            //var obligationsByRoom = ctx.Rooms.Where(r => r.Number == number)
            //    .Sum(r => r.Students.Sum(s => s.Obligations));
            //System.Console.WriteLine(obligationsByRoom);
            #endregion

            #region Get all students obligations
            //ctx.Students.ToList().Select(s => new
            //{
            //    s.FullName,
            //    s.Obligations
            //})
            //    .ToList()
            //    .ForEach(s => System.Console.WriteLine($"{s.FullName} obligations: {s.Obligations} leva."));
            #endregion

            #region Get All Unsigned Guests
            //ctx.Guests.Where(g => g.DateLeft == null).ToList().Select(g => new
            //{
            //    g.FullName,
            //    studentName=g.StudentVisited.FullName
            //}).ToList().ForEach(g =>
            //{
            //    System.Console.WriteLine($"{g.FullName} has probably not unsigned and {g.studentName} should be charged extra!");
            //});
            #endregion

            #region Get All Active Students By Room
            //var roomId = 1;
            //ctx.Students.Where(s => s.RoomId == roomId && s.IsActive == true).ToList().ForEach(s =>
            //{
            //    System.Console.WriteLine($"{s.FullName} is living in room {s.Room.Number} and has {s.Obligations} debt!");
            //});
            #endregion

            #region Students By Room In Campus
            //var roomNumber = "101";
            //var campusName = "Softuni";
            //ctx.Campuses.FirstOrDefault(c => c.University.Name == campusName)
            //    .Rooms
            //    .FirstOrDefault(r => r.Number == roomNumber)
            //    .Students.Count();
            #endregion
        }