Ejemplo n.º 1
0
        public async Task <IActionResult> CreateZoomMeeting(CreateingZoomMeetingDTO model)
        {
            model.Settings = new ZoomMeetingSettings
            {
                ParticipantVideo = false,
                //AlternativeHosts = Username
            };
            var response = await _zoomApiService.CreateMeetingAsync(ZoomUserId, model);

            if (response.StatusCode != HttpStatusCode.Created)
            {
                return(BadRequest(response.ErrorMessage));
            }

            var zoomMeetingInfo = JsonConvert.DeserializeObject <ZoomMeetingDTO>(response.Content);
            var zoomMeeting     = _mapper.Map <ZoomMeeting>(zoomMeetingInfo);

            zoomMeeting.CreatedBy = UserId;
            await _zoomMeetingRepository.AddAsync(zoomMeeting);

            return(Ok(zoomMeeting));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([FromForm] EventBindingModel model)
        {
            ZoomMeeting zoomMeeting = null;

            if (model.CreateZoomMeeting)
            {
                var createZoomMeetingModel = new CreateingZoomMeetingDTO
                {
                    Topic     = model.Title,
                    Agenda    = model.Description,
                    Duration  = Constants.DEFAULT_ZOOM_MEETING_DURATION,
                    StartTime = model.EventDate
                };

                createZoomMeetingModel.Settings = new ZoomMeetingSettings
                {
                    ParticipantVideo = false,
                    //AlternativeHosts = Username
                };

                var response = await _zoomApiService.CreateMeetingAsync(ZoomUserId, createZoomMeetingModel);

                if (response.StatusCode != System.Net.HttpStatusCode.Created)
                {
                    return(BadRequest(response.ErrorMessage));
                }

                var zoomMeetingInfo = JsonConvert.DeserializeObject <ZoomMeetingDTO>(response.Content);
                zoomMeeting           = _mapper.Map <ZoomMeeting>(zoomMeetingInfo);
                zoomMeeting.CreatedBy = UserId;
                await _zoomMeetingRepository.AddAsync(zoomMeeting);
            }

            var speakerIds = await _eventValueFieldsService.GetSpeakerIdsAsync(model.Speakers);

            var sponsorIds = await _eventValueFieldsService.GetSponsorIdsAsync(model.Sponsors);

            var entity = _mapper.Map <Event>(model);

            entity.CreatedBy = UserId;

            speakerIds.ForEach(x => entity.EventSpeakers.Add(new EventSpeaker {
                SpeakerId = x
            }));
            sponsorIds.ForEach(x => entity.EventSponsors.Add(new EventSponsor {
                SponsorId = x
            }));

            if (model.SessionId.NullOrEmpty())
            {
                entity.SessionId = Guid.NewGuid().ToString();
            }

            if (model.Files != null && model.Files.Count() > 0)
            {
                entity.EventFolder = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
                var folderPath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.EVENTS, entity.EventFolder);
                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                int i = 0;
                foreach (var item in model.Files)
                {
                    var filename = item.FileName.ToUniqueFileName();
                    var savePath = Path.Combine(_hostEnvironment.WebRootPath, UploadFolders.UPLOAD_PATH, UploadFolders.EVENTS, entity.EventFolder, filename);
                    await item.CopyToAsync(new FileStream(savePath, FileMode.Create));

                    entity.EventResources[i].Title       = entity.EventResources[i].Title.NullOrEmpty() ? "" : entity.EventResources[i].Title;
                    entity.EventResources[i].FilePath    = new string[] { UploadFolders.UPLOAD_PATH, UploadFolders.EVENTS, entity.EventFolder, filename }.ToWebFilePath();
                    entity.EventResources[i].PreviewType = filename.Contains(".pdf") ? "pdf" : "image";
                }
            }

            if (zoomMeeting != null)
            {
                entity.MeetingId       = zoomMeeting.Id;
                entity.MeetingPassword = zoomMeeting.Password;
            }

            await _repository.AddAsync(entity);

            return(Ok());
        }