Example #1
0
        public async void UpdateSchedule()
        {
            //Arrange
            var schedule = new Timetable()
            {
                Id        = 1,
                RoomId    = 1,
                Date      = DateTime.Now.Date,
                StartTime = TimeSpan.Parse("8:00"),
                EndTime   = TimeSpan.Parse("10:00"),
            };
            // Act
            var result = await TimetableDAO.Create(roomContext, schedule);

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            schedule.Date      = DateTime.Now.AddDays(1).Date;
            schedule.StartTime = TimeSpan.Parse("9:00");
            schedule.EndTime   = TimeSpan.Parse("12:00");

            result = TimetableDAO.Update(roomContext, schedule);
            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);
            var resultSchedule = TimetableDAO.GetById(roomContext, 1);

            Assert.Equal(1, resultSchedule.RoomId);
            Assert.Equal(DateTime.Now.AddDays(1).Date, resultSchedule.Date);
            Assert.Equal(TimeSpan.Parse("9:00"), resultSchedule.StartTime);
            Assert.Equal(TimeSpan.Parse("12:00"), resultSchedule.EndTime);
        }
Example #2
0
        public async static Task <IActionResult> DeleteRoom(RoomDBContext context, int roomId, IWebHostEnvironment env)
        {
            var room = RoomDAO.Get(context, roomId);

            if (room != null)
            {
                var roomUserLinks  = RoomUserLinkDAO.GetRoomLink(context, roomId);
                var roomChats      = RoomChatDAO.GetChatByRoomId(context, roomId);
                var roomTimetables = TimetableDAO.GetByRoomId(context, roomId);
                var groups         = RoomDAO.GetGroupByRoom(context, roomId);

                var result = await RoomUserLinkDAO.Delete(context, roomUserLinks);

                result = await RoomChatDAO.DeleteRoomChat(context, roomChats);

                result = await TimetableDAO.DeleteTimeTable(context, roomTimetables);

                foreach (var group in groups)
                {
                    result = await DeleteRoom(context, group.RoomId, env);
                }

                var path = Path.Combine(env.ContentRootPath, $"Files/{roomId}");
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }

                result = await RoomDAO.Delete(context, room);

                return(result);
            }
            return(new BadRequestObjectResult(new { message = "Class now exist!" }));
        }
Example #3
0
        public async void ScheduleDeleteList()
        {
            var schedules = new List <Timetable>();

            //Arrange
            schedules.Add(new Timetable()
            {
                Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"),
            });
            schedules.Add(new Timetable()
            {
                Id = 2, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"),
            });
            schedules.Add(new Timetable()
            {
                Id = 3, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"),
            });
            // Act
            var result = await TimetableDAO.Create(roomContext, schedules);

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            schedules.RemoveAt(2);

            result = await TimetableDAO.DeleteTimeTable(roomContext, schedules);

            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            var resultSchedule = TimetableDAO.GetById(roomContext, 1);

            Assert.Null(resultSchedule);
            resultSchedule = TimetableDAO.GetById(roomContext, 3);
            Assert.NotNull(resultSchedule);
        }
Example #4
0
        public async void GetByRoomAndDate()
        {
            var schedules = new List <Timetable>();

            //Arrange
            schedules.Add(new Timetable()
            {
                Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"),
            });
            schedules.Add(new Timetable()
            {
                Id = 2, RoomId = 1, Date = DateTime.Now.AddDays(1).Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"),
            });
            schedules.Add(new Timetable()
            {
                Id = 3, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"),
            });
            // Act
            var result = await TimetableDAO.Create(roomContext, schedules);

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);

            var resultList = TimetableDAO.GetByRoomAndDate(roomContext, 1, DateTime.Now.Date);

            Assert.Equal(2, resultList.Count);
        }
Example #5
0
        public async void DeleteSchedule()
        {
            var models = new List <string>();

            models.Add("1");
            var result = await _SemetserService.Object.DeleteSchedule(models);

            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);
            var schedule = TimetableDAO.GetById(roomContext, 1);

            Assert.Null(schedule);
        }
Example #6
0
 public static string DeleteTimetable(string timetableid, int userid)
 {
     if (!TimetableField.Id.TestValue(timetableid))
     {
         return("");
     }
     SqlQueryCondition[] sqlconditions = new SqlQueryCondition[] {
         new SqlQueryCondition(TimetableField.Id, SqlQueryConditionOperator.Equal, timetableid),
         new SqlQueryCondition(TimetableField.Status, SqlQueryConditionOperator.NotEqual, 1),
         new SqlQueryCondition(TimetableField.Owner, SqlQueryConditionOperator.Equal, userid)     //加入此条件防止非法更改他人课表
     };
     TimetableDAO.Delete(new SqlQueryCondition(sqlconditions, SqlQueryLogicalOperator.And));
     UserLogDAO.Insert(userid, "deltb{" + timetableid + "}");
     return("true");
 }
Example #7
0
 public static string UpdateTimetableData(string timetableid, string newdata, int userid)
 {
     if (!TimetableField.Id.TestValue(timetableid) || !TimetableField.Data.TestValue(newdata))
     {
         return("数据错误 请联系管理员!");
     }
     SqlQueryCondition[] sqlconditions = new SqlQueryCondition[] {
         new SqlQueryCondition(TimetableField.Owner, SqlQueryConditionOperator.Equal, userid),     //加入此条件防止非法更改他人课表
         new SqlQueryCondition(TimetableField.Id, SqlQueryConditionOperator.Equal, timetableid)
     };
     TimetableDAO.Update(new TimetableField[] { TimetableField.Data }, new object[] { newdata },
                         new SqlQueryCondition(sqlconditions, SqlQueryLogicalOperator.And));
     UserLogDAO.Insert(userid, "updtb{" + timetableid + "}");
     return("true");
 }
Example #8
0
 public static object[,] GetTimetableData(string timetableid, int userid)
 {
     if (!TimetableField.Id.TestValue(timetableid))
     {
         return new object[, ] {
                    { "" }
         }
     }
     ;
     SqlQueryCondition[] sqlconditions = new SqlQueryCondition[] {
         new SqlQueryCondition(TimetableField.Id, SqlQueryConditionOperator.Equal, timetableid),
         new SqlQueryCondition(TimetableField.Owner, SqlQueryConditionOperator.Equal, userid)     //加入此条件防止非法查看他人课表
     };
     UserLogDAO.Insert(userid, "gettbdat{" + timetableid + "}");
     return(TimetableDAO.Select(new TimetableField[] { TimetableField.Data }, new SqlQueryCondition(sqlconditions, SqlQueryLogicalOperator.And)));
 }
Example #9
0
        public async Task <IActionResult> GetTimeTable(TimetableRequest model)
        {
            var appUser = await _userManager.FindByIdAsync(_userAccessor.GetCurrentUserId());

            var userLinks = (from userRooms in _roomDbContext.RoomUserLink
                             where userRooms.UserId == appUser.Id
                             select userRooms.RoomId).ToList();

            //Toàn bộ room người dùng này tham gia vào
            var rooms = new List <Room>();

            foreach (var roomId in userLinks)
            {
                //get room
                var room = await _roomDbContext.Room.Where(r => r.RoomId == roomId && !r.Group).FirstOrDefaultAsync();

                if (room != null)
                {
                    rooms.Add(room);
                }
            }


            var resultList = new List <TimetableResponse>();

            foreach (var room in rooms)
            {
                var roomTimetables = TimetableDAO.GetByRoomId(_roomDbContext, room.RoomId);

                foreach (var timetable in roomTimetables)
                {
                    if (timetable.Date >= model.StartDate && timetable.Date <= model.EndDate)
                    {
                        resultList.Add(new TimetableResponse
                        {
                            RoomId    = room.RoomId.ToString(),
                            EventType = 0,
                            Title     = room.Subject + "-" + room.ClassName,
                            TeacherId = room.CreatorId,
                            StartDate = timetable.Date.ToString("yyyy-MM-dd") + "T" + timetable.StartTime,
                            EndDate   = timetable.Date.ToString("yyyy-MM-dd") + "T" + timetable.EndTime,
                        });
                    }
                }
            }
            return(new OkObjectResult(resultList));
        }
Example #10
0
        public async void ScheduleCreateSuccessfully()
        {
            //Arrange
            var schedule = new Timetable()
            {
                Id        = 1,
                RoomId    = 1,
                Date      = DateTime.Now.Date,
                StartTime = TimeSpan.Parse("8:00"),
                EndTime   = TimeSpan.Parse("10:00"),
            };
            // Act
            var result = await TimetableDAO.Create(roomContext, schedule);

            // Assert
            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);
        }
Example #11
0
 public static string AddTimetable(string timetablename, string data, int userid)
 {
     if (!TimetableField.Name.TestValue(timetablename) || !TimetableField.Data.TestValue(data))
     {
         return("数据错误 请联系管理员!");
     }
     SqlQueryCondition[] sqlconditions = new SqlQueryCondition[] {
         new SqlQueryCondition(TimetableField.Owner, SqlQueryConditionOperator.Equal, userid),
         new SqlQueryCondition(TimetableField.Name, SqlQueryConditionOperator.Equal, timetablename)
     };
     if (TimetableDAO.Select(new TimetableField[] { TimetableField.Id }, new SqlQueryCondition(sqlconditions, SqlQueryLogicalOperator.And)).Length != 0)
     {
         return("课表名重复!");
     }
     else
     {
         UserLogDAO.Insert(userid, "addtb{" + timetablename + "}");
         return("true:" + TimetableDAO.Insert(timetablename, userid, data)); //加上id一起返回
     }
 }
Example #12
0
        public async Task <IActionResult> GetAttendanceByRoom(int id)
        {
            var timetables     = TimetableDAO.GetByRoomId(_roomContext, id);
            var attendanceList = new List <AttendanceTeacherResponse>();

            foreach (var timetable in timetables)
            {
                var room = await _roomContext.Room.FirstOrDefaultAsync(x => x.RoomId == timetable.RoomId);

                if (room == null)
                {
                    break;
                }
                var listStudent = new List <AttendanceStudent>();

                var listStudentId = await(from attendances in _userContext.AttendanceReports
                                          where attendances.TimeTableId == timetable.Id
                                          select new AttendanceStudent
                {
                    Id     = attendances.UserId,
                    Status = attendances.Status
                }).ToListAsync();
                foreach (var student in listStudentId)
                {
                    student.Id = _userManager.FindByIdAsync(student.Id).Result.UserName;
                }
                listStudent.AddRange(listStudentId);
                attendanceList.Add(new AttendanceTeacherResponse
                {
                    Id        = timetable.Id.ToString(),
                    Class     = room.ClassName,
                    Subject   = room.Subject,
                    Date      = String.Format("{0:yyyy-MM-dd}", timetable.Date),
                    StartTime = timetable.StartTime.ToString(@"hh\:mm"),
                    EndTime   = timetable.EndTime.ToString(@"hh\:mm"),
                    Teacher   = _userManager.FindByIdAsync(room.CreatorId).Result.UserName,
                    Students  = listStudent
                });
            }
            return(new OkObjectResult(attendanceList));
        }
Example #13
0
    public static string ActiveTimetable(string timetableid, int userid)
    {
        if (!TimetableField.Id.TestValue(timetableid))
        {
            return("");
        }
        SqlQueryCondition sqlcondition1 = new SqlQueryCondition(TimetableField.Id, SqlQueryConditionOperator.Equal, timetableid);
        SqlQueryCondition sqlcondition2 = new SqlQueryCondition(TimetableField.Status, SqlQueryConditionOperator.Equal, 1);
        SqlQueryCondition sqlcondition3 = new SqlQueryCondition(TimetableField.Owner, SqlQueryConditionOperator.Equal, userid); //加入此条件防止非法更改他人课表

        if (TimetableDAO.Select(new TimetableField[] { TimetableField.Id },
                                new SqlQueryCondition(new SqlQueryCondition[] { sqlcondition1, sqlcondition3 }, SqlQueryLogicalOperator.And)).Length != 0)
        {
            TimetableDAO.Update(new TimetableField[] { TimetableField.Status }, new object[] { 0 },
                                new SqlQueryCondition(new SqlQueryCondition[] { sqlcondition2, sqlcondition3 }, SqlQueryLogicalOperator.And));
            TimetableDAO.Update(new TimetableField[] { TimetableField.Status }, new object[] { 1 },
                                new SqlQueryCondition(new SqlQueryCondition[] { sqlcondition1 }, SqlQueryLogicalOperator.And));
        }
        UserLogDAO.Insert(userid, "acttb{" + timetableid + "}");
        return("true");
    }
Example #14
0
        public async void UpdateScheduleFailOverlap()
        {
            var models = new List <ScheduleRequest>();

            models.Add(new ScheduleRequest()
            {
                id        = "1",
                date      = DateTime.Now.Date.ToString(),
                startTime = "8:30",
                endTime   = "10:30",
                subject   = "testSubjectasd",
                @class    = "testName"
            });
            var result = await _SemetserService.Object.UpdateSchedule(1, models);

            Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode);
            var schedule = TimetableDAO.GetById(roomContext, 1);

            Assert.NotEqual(schedule.StartTime.ToString(), "8:30:00");
            Assert.NotEqual(schedule.EndTime.ToString(), "10:30:00");
        }
Example #15
0
    public static string RenameTimetable(string timetableid, string newname, int userid)
    {
        if (!TimetableField.Id.TestValue(timetableid) || !TimetableField.Name.TestValue(newname))
        {
            return("数据错误 请联系管理员!");
        }
        SqlQueryCondition sqlcondition1 = new SqlQueryCondition(TimetableField.Owner, SqlQueryConditionOperator.Equal, userid); //加入此条件防止非法更改他人课表
        SqlQueryCondition sqlcondition2 = new SqlQueryCondition(TimetableField.Id, SqlQueryConditionOperator.Equal, timetableid);
        SqlQueryCondition sqlcondition3 = new SqlQueryCondition(TimetableField.Name, SqlQueryConditionOperator.Equal, newname);

        if (TimetableDAO.Select(new TimetableField[] { TimetableField.Id },
                                new SqlQueryCondition(new SqlQueryCondition[] { sqlcondition1, sqlcondition3 }, SqlQueryLogicalOperator.And)).Length != 0)
        {
            return("课表名重复!");
        }
        else
        {
            TimetableDAO.Update(new TimetableField[] { TimetableField.Name }, new object[] { newname },
                                new SqlQueryCondition(new SqlQueryCondition[] { sqlcondition1, sqlcondition2 }, SqlQueryLogicalOperator.And));
            UserLogDAO.Insert(userid, "rntb{" + timetableid + '\r' + newname + "}");
            return("true");
        }
    }
Example #16
0
        public SemesterServiceTest()
        {
            factory     = new ConnectionFactory();
            userContext = factory.CreateUserDbContextForInMemory();
            userContext.Database.EnsureDeleted();
            userContext.Database.EnsureCreated();
            userContext.SaveChanges();

            roomContext = factory.CreateRoomDbContextForInMemory();
            roomContext.Database.EnsureDeleted();
            roomContext.Database.EnsureCreated();
            roomContext.SaveChanges();

            attendanceDAO = new Mock <AttendanceDAO>(userContext);
            logDAO        = new Mock <LogDAO>(userContext);
            var iAttendanceDao = attendanceDAO.As <IAttendanceDAO>();
            var iLogDAO        = logDAO.As <ILogDAO>();
            //mocking user manager
            var users = new List <AppUser>
            {
                new AppUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                },
                new AppUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                },
                new AppUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                },
                new AppUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                },
                new AppUser
                {
                    UserName = "******",
                    Email    = "*****@*****.**"
                },
            }.AsQueryable();

            var fakeUserManager = new Mock <FakeUserManager>();

            fakeUserManager.Setup(x => x.Users).Returns(users.AsQueryable());

            fakeUserManager.Setup(x => x.DeleteAsync(It.IsAny <AppUser>()))
            .ReturnsAsync(IdentityResult.Success);
            fakeUserManager.Setup(x => x.CreateAsync(It.IsAny <AppUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);
            fakeUserManager.Setup(x => x.UpdateAsync(It.IsAny <AppUser>()))
            .ReturnsAsync(IdentityResult.Success);

            var mockEnvironment = new Mock <IWebHostEnvironment>();

            //...Setup the mock as needed
            mockEnvironment
            .Setup(m => m.EnvironmentName)
            .Returns("Hosting:UnitTestEnvironment");
            mockEnvironment.Setup(m => m.ContentRootPath).Returns("");
            _SemetserService = new Mock <SemesterService>(fakeUserManager.Object, userContext, roomContext, mockEnvironment.Object, iAttendanceDao.Object, iLogDAO.Object);
            var semester = new Semester()
            {
                Id          = 1,
                Name        = "testSemester",
                File        = "TestFile.xsl",
                LastUpdated = DateTime.Now
            };

            SemesterDAO.Create(roomContext, semester);

            var room = new Room()
            {
                RoomId     = 1,
                Subject    = "testSubject",
                ClassName  = "testName",
                CreatorId  = "testUser",
                SemesterId = 1
            };

            RoomDAO.Create(roomContext, room);

            var links = new List <RoomUserLink>();

            links.Add(new RoomUserLink()
            {
                RoomId = 1, RoomUserId = 1, UserId = "testUser"
            });
            links.Add(new RoomUserLink()
            {
                RoomId = 1, RoomUserId = 2, UserId = "testUser2"
            });
            links.Add(new RoomUserLink()
            {
                RoomId = 1, RoomUserId = 3, UserId = "testUser1"
            });

            // Act
            RoomUserLinkDAO.Create(roomContext, links);

            var schedule = new Timetable()
            {
                Id        = 1,
                RoomId    = 1,
                Date      = DateTime.Now.Date,
                StartTime = TimeSpan.Parse("8:00"),
                EndTime   = TimeSpan.Parse("10:00"),
            };

            // Act
            TimetableDAO.Create(roomContext, schedule);
        }
Example #17
0
 public static object[,] GetTimetables(int userid)
 {
     UserLogDAO.Insert(userid, "gettbs{}");
     TimetableField[] fields = new TimetableField[] { TimetableField.Id, TimetableField.Name, TimetableField.Status };
     return(TimetableDAO.Select(fields, new SqlQueryCondition(TimetableField.Owner, SqlQueryConditionOperator.Equal, userid)));
 }