예제 #1
0
        static void InsertRooms(FptFapClient fapClient)
        {
            var fapRooms = fapClient.GetAllRooms().Result;
            var rooms    = fapRooms.Select(o => o.ToRoom())
                           .Distinct(new RoomComparer()).ToList();
            var builder = new DbContextOptionsBuilder <DataContext>().UseSqlServer(
                DataConsts.CONN_STR);
            var options = builder.Options;

            using (var context = new DataContext(options))
            {
                context.Room.AddRange(rooms);
                context.SaveChanges();
            }
        }
예제 #2
0
 public static void Init(IServiceCollection services, string fapSecret)
 {
     Random = new Random();
     if (fapSecret != null)
     {
         try
         {
             FapClient = new FptFapClient(Settings.Instance.FapApiUrl, fapSecret);
             FapClient.CacheData().Wait();
             services.AddSingleton(FapClient);
         }
         catch (Exception e)
         {
             Console.WriteLine(e.Message);
         }
     }
     InitAutoMapper();
     InitDI(services);
 }
예제 #3
0
        static void Main(string[] args)
        {
            var test = "*****@*****.**";
            var code = test.IsStudent();

            Console.WriteLine(code);
            using (var fapClient = new FptFapClient("http://fap.fpt.edu.vn", "fap-secret-key"))
            {
                //var test = fapClient.GetScheduleInDateRangeAsync(
                //    new DateTime(2020, 7, 7),
                //    new DateTime(2020, 7, 10),
                //    "KhanhT").Result;

                //var test = fapClient.GetAllSlots().Result;
                //fapClient.CacheData().Wait();
                //var test = fapClient.GetActivityTeacher(DateTime.Now, "KhanhT").Result;
                //test = fapClient.GetActivityStudent(DateTime.Now, "SE130097").Result;
                //InsertRooms(fapClient);
            }
        }
        public async Task <int> SyncRoomWithFapAsync(FptFapClient fapClient)
        {
            var rooms = await fapClient.GetAllRooms();

            var area3Rooms = rooms.Where(o => o.AreaId == 3).ToList();

            foreach (var r in area3Rooms)
            {
                var  existed = Rooms.Code(r.RoomNo).Any();
                Room entity  = r.ToRoom();
                if (existed)
                {
                    var oldRes = RoomResources.OfRoom(entity.Code).ToList();
                    DeleteRoomServices(oldRes);
                    context.Room.Update(entity);
                }
                else
                {
                    context.Room.Add(entity);
                }
            }
            return(area3Rooms.Count);
        }