/// <summary> /// Check the capacity of the room by each day of the reservation period /// </summary> /// <param name="res"></param> public static bool CheckRoomAvailability(Reservation res) { DormRoom room = DormRoomMapper.GetRoomByID(res.RoomID); // loop each date starting for res.startdate for (DateTime date = res.StartDate; date <= res.EndDate; date = date.AddDays(1)) { var existing = from reservation in room.Reservations where reservation.StartDate <= date && reservation.EndDate >= date select reservation; //foreach (Reservation reservation in existing) // Console.WriteLine($"Starts: {reservation.StartDate} " + // $"Ends: {reservation.EndDate} " + // $"Checking: {date} " + // $"StartDate < date && EndDate > date returns: {reservation.StartDate < date && reservation.EndDate > date}") // check how many reservations exist in the date if (existing.Count() >= room.Capacity) { return(false); } } return(true); }
public static void DeleteDormRoomByID(int roomid) { var rooms = from r in context.DormRoom where r.RoomID == roomid select r; DormRoom room = rooms.FirstOrDefault(); if (room != null) { context.DormRoom.Remove(room); context.SaveChanges(); } }
private void InsertRoomButtonClicked(object sender, EventArgs e) { DormRoom newRoom = new DormRoom { Size = int.Parse(RoomSizeTextBox.Text), Capacity = int.Parse(roomCapacityTextBox.Text), FloorID = int.Parse(FloorIDTextBox.Text), RoomNumber = int.Parse(roomNumbertextBox.Text) }; DormRoomMapper.CreateDormRoom(newRoom); UpdateRoomList(DormRoomMapper.GetAllRooms()); }
/// <summary> /// 简化程序(把学生数据分为六张表,分为六个方法进行) Dorm_Dorm /// </summary> /// <param name="db"></param> /// <param name="newDb"></param> public void ProcessSchoolStudentDormInfo(EFContext db, NHModel newDb) { var newData = newDb.Set <StudentInfo>().AsNoTracking().Select(p => new DormStudentMoudle { StudentId = p.studentId, Description = p.studentBuildingId, Gender = p.studentSex }).ToList(); //添加到 zhxy_Building表 var BuildData = newData.Where(p => p.Description != null && p.Description.Contains("栋")).Select(p => p.Description.Split('栋')[0].Replace(" ", "").Replace("海院A", "海A").Replace("海院B", "海B")).Distinct().ToList(); //新增至宿舍楼栋表(dorm_building) var oldBuildData = db.Set <Building>().AsNoTracking().Select(p => p.BuildingNo).ToList(); var AddBuild = BuildData.Except(oldBuildData).ToList(); if (null != AddBuild && AddBuild.Count() > 0) { var add = new List <Building>(); foreach (var s in AddBuild) { var b = new Building(); b.BuildingNo = s; add.Add(b); } db.Set <Building>().AddRange(add); db.SaveChanges(); } //添加到 zhxy_dorm 表 var NewRoomTitle = newData.Where(p => p.Description != null && p.Description.Contains("栋")).Select(p => p.Description).Distinct().ToList(); var RoomTitle = db.Set <DormRoom>().AsNoTracking().Select(p => p.Building.BuildingNo + "栋" + p.RoomNumber).ToList(); var AddRoomInfo = NewRoomTitle.Except(RoomTitle).ToList(); if (AddRoomInfo != null && AddRoomInfo.Count() > 0) { var AddDorm = new List <DormRoom>(); foreach (var title in AddRoomInfo) { var BuildNo = title.Split('栋'); if (BuildNo != null && BuildNo.Count() == 2) { var d = new DormRoom(); var build = BuildNo[0]; d.BuildingId = db.Set <Building>().AsNoTracking().Where(p => p.BuildingNo.Equals(build)).Select(s => s.Id).FirstOrDefault(); d.FloorNumber = BuildNo[1].Replace(BuildNo[1].Substring(1), ""); d.RoomNumber = BuildNo[1]; d.Title = title; AddDorm.Add(d); } } db.Set <DormRoom>().AddRange(AddDorm); db.SaveChanges(); } //添加到zhxy_dorm_student 表 var ListDataNew = new List <DormStudentMoudle>(); foreach (var n in newData) { var D = new DormStudentMoudle(); D.DormId = db.Set <DormRoom>().AsNoTracking().Where(p => p.Title.Equals(n.Description)).Select(p => p.Id).FirstOrDefault(); D.StudentId = n.StudentId; D.Gender = n.Gender; ListDataNew.Add(D); } var ListDataOld = db.Set <DormStudent>().AsNoTracking().Select(p => new DormStudentMoudle { DormId = p.DormId, StudentId = p.StudentId, Gender = p.Gender }).ToList(); var AddList = ListDataNew.Except(ListDataOld).ToList(); var FinalAddList = new List <DormStudent>(); foreach (var s in AddList) { var StudentIds = ListDataOld.Select(p => p.StudentId).ToList(); if (StudentIds.Contains(s.StudentId)) { db.Set <DormStudent>().Where(p => p.StudentId.Equals(s.StudentId)).Update(p => new DormStudent { DormId = s.DormId, Gender = s.Gender }); } else { FinalAddList.Add(new DormStudent() { DormId = s.DormId, Gender = s.Gender, StudentId = s.StudentId }); } } db.Set <DormStudent>().AddRange(FinalAddList); db.SaveChanges(); }
public static void CreateDormRoom(DormRoom room) { context.DormRoom.Add(room); context.SaveChanges(); }