public ApiResponse <MeetingCalendarModel> AddMeeting(ReserveMeetingModel model) { // 1. 检查输入参数 if (model == null) { throw new ApiBadRequestException("无请求数据"); } if (model.MeetingRoomId == 0) { throw new ApiBadRequestException("会议室不存在"); } if (model.StartDate.Date != model.EndDate.Date) { throw new ApiBadRequestException("开始日期与结束日期需在同一天"); } if (model.StartDate >= model.EndDate) { throw new ApiBadRequestException("开始时间必须小于结束时间"); } if (model.StartDate < DateTime.Now.AddMinutes(10)) { throw new ApiBadRequestException("必须提前十分钟预定会议室"); } if (MeetingService.isMeetingRoomAvailiable(model.MeetingRoomId, model.StartDate, model.EndDate) == false) { throw new ApiBadRequestException("会议室已经占用"); } // 2. 构造会议预约记录 var meetingCalendar = new MeetingCalendarModel() { ApplyUserId = this.Member.Id, MeetingRoomId = model.MeetingRoomId, Title = model.Title, Host = model.Host, StartDate = model.StartDate, EndDate = model.EndDate, MeetingContext = model.MeetingContext, StartTime = model.StartDate.TimeOfDay, EndTime = model.EndDate.TimeOfDay, CreatedTime = DateTime.Now }; //2.1 构造会议必须参与人员模型 List <MeetingParticipantModel> meetingParticipants = new List <MeetingParticipantModel>(); if (model.participants != null && (model.participants.Length > 0)) { foreach (int item in model.participants) { var meetingParticipantModel = new MeetingParticipantModel() { UserId = item, IsOptional = "No" }; meetingParticipants.Add(meetingParticipantModel); } } //2.1 构造会议可选参与人员模型 if (model.optionalParticipants != null && (model.optionalParticipants.Length > 0)) { foreach (int item in model.optionalParticipants) { var meetingParticipantModel = new MeetingParticipantModel() { UserId = item, IsOptional = "Yes" }; meetingParticipants.Add(meetingParticipantModel); } } meetingCalendar.MeetingParticipants = meetingParticipants; //新增会议预约 // 3. Construct API Response ApiResponse <MeetingCalendarModel> response = new ApiResponse <MeetingCalendarModel>() { Result = MeetingService.AddMeeting(meetingCalendar, false) }; return(response); }
public ApiResponse <bool> AddMeetingByWeeks(ReserveMeetingModel model, int loopCount) { // 1. 检查输入参数 if (model == null) { throw new ApiBadRequestException("无请求数据"); } if (model.MeetingRoomId == 0) { throw new ApiBadRequestException("会议室不存在"); } if (loopCount > 10) { throw new ApiBadRequestException("会议循环次数不能大于十次"); } if (model.MeetingDayInWeek == null || model.MeetingDayInWeek.Length < 1) { throw new ApiBadRequestException("请选择会议举办日期"); } if (model.StartDate >= model.EndDate) { throw new ApiBadRequestException("会议开始时间必须小于结束时间"); } bool isMeetingAdded = false; if (model.MeetingDayInWeek != null && model.MeetingDayInWeek.Length > 0) { DateTime today = DateTime.Now; int TodayInDayOfWeek = (int)today.DayOfWeek; DateTime WeekStartDateStartTime = today.AddDays(-TodayInDayOfWeek).Date + model.StartDate.TimeOfDay; //当前星期的星期天会议开始时间 DateTime WeekStartDateEndTime = today.AddDays(-TodayInDayOfWeek).Date + model.EndDate.TimeOfDay; //当前星期的星期天会议结束时间 for (int i = 0; i <= loopCount; i++) { for (int j = 0; j < model.MeetingDayInWeek.Length; j++) { DateTime StartDate = WeekStartDateStartTime.AddDays((int)model.MeetingDayInWeek[j]); DateTime EndDate = WeekStartDateEndTime.AddDays((int)model.MeetingDayInWeek[j]); if (StartDate > today) { if (MeetingService.isMeetingRoomAvailiable(model.MeetingRoomId, StartDate, EndDate) == false) { throw new ApiBadRequestException("会议室已经占用"); } else { // 2. 构造会议预约记录 var meetingCalendar = new MeetingCalendarModel() { ApplyUserId = this.Member.Id, MeetingRoomId = model.MeetingRoomId, Title = model.Title, Host = model.Host, StartDate = StartDate, EndDate = EndDate, MeetingContext = model.MeetingContext, StartTime = model.StartDate.TimeOfDay, EndTime = model.EndDate.TimeOfDay, CreatedTime = DateTime.Now }; //2.1 构造会议必须参与人员模型 List <MeetingParticipantModel> meetingParticipants = new List <MeetingParticipantModel>(); if (model.participants != null && (model.participants.Length > 0)) { foreach (int item in model.participants) { var meetingParticipantModel = new MeetingParticipantModel() { UserId = item, IsOptional = "No" }; meetingParticipants.Add(meetingParticipantModel); } } //2.1 构造会议可选参与人员模型 if (model.optionalParticipants != null && (model.optionalParticipants.Length > 0)) { foreach (int item in model.optionalParticipants) { var meetingParticipantModel = new MeetingParticipantModel() { UserId = item, IsOptional = "Yes" }; meetingParticipants.Add(meetingParticipantModel); } } meetingCalendar.MeetingParticipants = meetingParticipants; MeetingService.AddMeeting(meetingCalendar, true); isMeetingAdded = true; } } } WeekStartDateStartTime = WeekStartDateStartTime.AddDays(7); //下次预定会议的星期天 WeekStartDateEndTime = WeekStartDateEndTime.AddDays(7); //下次的星期天会议结束数据 } } if (isMeetingAdded) { if (model.participants != null && (model.participants.Length > 0)) { foreach (int item in model.participants) { var userEntity = this.UserService.GetUserDetail(item); var notificationModel = new NotificationModel() { Target = userEntity.Email, CreatedUserId = this.Member.Id, //MessageType = NotificationType.PushMessage, MessageType = NotificationType.Email, BusinessType = BusinessType.BookMeetingRoomSuccessAnnounce, Title = "Missionsky OA Notification", MessagePrams = "test", Scope = NotificationScope.User, CreatedTime = DateTime.Now, TargetUserIds = new List <int> { userEntity.Id } }; if (loopCount > 0) { string MeetingHappenedDate = null; for (int i = 0; i < model.MeetingDayInWeek.Length; i++) { MeetingHappenedDate = MeetingHappenedDate + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(model.MeetingDayInWeek[i]) + ","; } notificationModel.MessageContent = string.Format("请参加,于每周{0}{1}召开,由{2}主持的{3}会议,会议持续循环召开{4}周", MeetingHappenedDate, model.StartDate.TimeOfDay, model.Host, model.Title, loopCount + 1); } else { string MeetingHappenedDate = null; for (int i = 0; i < model.MeetingDayInWeek.Length; i++) { if (model.MeetingDayInWeek[i] >= DateTime.Now.DayOfWeek) { MeetingHappenedDate = MeetingHappenedDate + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(model.MeetingDayInWeek[i]) + ","; } } notificationModel.MessageContent = string.Format("请参加,于本周{0}{1}召开,由{2}主持的{3}会议", MeetingHappenedDate, model.StartDate.TimeOfDay, model.Host, model.Title, loopCount + 1); } this._notificationService.Add(notificationModel, Global.IsProduction); //消息推送 } } } //新增会议预约 // 3. Construct API Response ApiResponse <bool> response = new ApiResponse <bool>() { Result = isMeetingAdded }; return(response); }