Example #1
0
        private async Task <OperationResultWithData <SlotDto> > UpdateSlotStatusInternal(int slotId, OfficeHoursSlotStatus status, LmsUser lmsUser)
        {
            var slot = _slotModel.GetOneById(slotId).Value;

            if (slot == null)
            {
                return(OperationResultWithData <SlotDto> .Error("Slot not found"));
            }

            slot.Status = (int)status;
            _slotModel.RegisterSave(slot, true);
            return(ConvertToDto(slot, lmsUser.Id).ToSuccessResult());
        }
Example #2
0
        public async Task <OperationResultWithData <IEnumerable <SlotDto> > > AddSlots(int ohId, LmsUser lmsUser, IEnumerable <CreateSlotDto> dtos, OfficeHoursSlotStatus status = OfficeHoursSlotStatus.Booked)
        {
            var availabilities = _availabilityModel.GetAvailabilities(ohId); //await _context.OhTeacherAvailabilities.Include(x => x.Meeting).Where(x => x.Meeting.Id == meetingId).ToListAsync();// &&x.lmsUserId == lmsUserId
            var entities       = new List <OfficeHoursSlot>();

            foreach (var dto in dtos)
            {
                //validate interval and non-busy
                var availability = availabilities.FirstOrDefault(x =>
                {
                    var availabilityDto = ConvertToDto(x);
                    var slots           = GetSlotsForAvailability(availabilityDto, dto.Start, dto.End, lmsUser.Id, x);
                    return(slots.Any(s => s.Start == dto.Start && s.Status == (int)OfficeHoursSlotStatus.Free));
                });
                if (availability == null)
                {
                    return(OperationResultWithData <IEnumerable <SlotDto> > .Error(
                               "Time is already booked or out of any availability range. Please refresh page."));
                }

                var entity = new OfficeHoursSlot
                {
                    Availability = availability,
                    //RequesterName = requesterName,
                    User      = lmsUser,
                    Start     = dto.Start,
                    End       = dto.End,
                    Subject   = dto.Subject,
                    Questions = dto.Questions,
                    Status    = (int)status
                };

                _slotModel.RegisterSave(entity, false);
                entities.Add(entity);
            }

            _slotModel.Flush();
            return(entities.Select(x => ConvertToDto(x, lmsUser.Id)).ToSuccessResult());
        }
Example #3
0
        public async Task <OperationResultWithData <SlotDto> > UpdateSlotStatus(int slotId, OfficeHoursSlotStatus status, LmsUser lmsUser, string message)
        {
            var slot = _slotModel.GetOneById(slotId).Value;

            if (slot == null)
            {
                return(OperationResultWithData <SlotDto> .Error("Slot not found"));
            }

            slot.Status = (int)status;
            _slotModel.RegisterSave(slot, true);
            if (!string.IsNullOrEmpty(message))
            {
                //var meeting = slot.Availability.Meeting;
                //var details = await _meetingService.GetMeetingApiDetails(meeting);
                //await _notificationService.SendOHCancellationEmail(slot.Start, details.Topic, message, slot.RequesterName);
            }
            return(ConvertToDto(slot, lmsUser.Id).ToSuccessResult());
        }