public string UpdateName(LmsCourseMeeting meeting, string lmsMeetingTitle) { if (meeting == null) { throw new ArgumentNullException(nameof(meeting)); } if (string.IsNullOrWhiteSpace(lmsMeetingTitle)) { throw new ArgumentException("Meeting Title is required", nameof(lmsMeetingTitle)); } MeetingNameInfo nameInfo = _nameInfoDeserializer.JsonDeserialize <MeetingNameInfo>(meeting.MeetingNameJson); nameInfo.meetingName = lmsMeetingTitle; meeting.MeetingNameJson = _nameInfoSerializer.JsonSerialize(nameInfo); if (meeting.LmsMeetingType == (int)LmsMeetingType.OfficeHours) { return(lmsMeetingTitle.TruncateIfMoreThen(60)); } int extraDataLength = ((string)nameInfo.courseNum).Length + ": ".Length + " - ".Length + ((string)nameInfo.courseId).Length; if (extraDataLength > 52) { throw new WarningMessageException("Can't generate Adobe Connect meeting name. Course Label is too long."); } return(string.Format("{0}: {1} - {2}", (string)nameInfo.courseNum, lmsMeetingTitle.TruncateIfMoreThen(60 - extraDataLength), (string)nameInfo.courseId)); }
public async Task <OperationResultWithData <IEnumerable <MeetingDto> > > FindMeetingByText(string consumerKey, string text) { _logger.InfoFormat("Consumer key: {0}, text: {1}", consumerKey, text); CompanyLms license = _dbContext.CompanyLms.First(c => c.ConsumerKey == consumerKey); int licenseId = license.CompanyLmsId; var couseMeetings = _dbContext.LmsCourseMeeting.Where(cm => cm.CompanyLmsId == licenseId).ToList(); var lmsCourseMeetingDtos = couseMeetings.Select(cm => new LmsCourseMeetingDto { LmsCourseMeetingId = cm.LmsCourseMeetingId, CompanyLmsId = cm.CompanyLmsId, CourseId = cm.CourseId, ScoId = cm.ScoId, OfficeHoursId = cm.OfficeHoursId, MeetingNameInfo = _jsonDeserializer.JsonDeserialize <MeetingNameInfoDto>(cm.MeetingNameJson) }); var foundCoursesIds = lmsCourseMeetingDtos.Where(r => !string.IsNullOrEmpty(r.MeetingNameInfo.courseName) && r.MeetingNameInfo.courseName.Contains(text, StringComparison.OrdinalIgnoreCase)).Select(f => f.LmsCourseMeetingId); var foundMeetingsIds = lmsCourseMeetingDtos.Where(r => !string.IsNullOrEmpty(r.MeetingNameInfo.meetingName) && r.MeetingNameInfo.meetingName.Contains(text, StringComparison.OrdinalIgnoreCase)).Select(f => f.LmsCourseMeetingId); var resultIds = new List <int>(); resultIds.AddRange(foundCoursesIds); resultIds.AddRange(foundMeetingsIds); resultIds = resultIds.Distinct().ToList(); IEnumerable <LmsCourseMeetingDto> filtredMeetings = lmsCourseMeetingDtos.Where(r => resultIds.Contains(r.LmsCourseMeetingId)).ToList(); IEnumerable <int> OfficeHoursMeetingIds = filtredMeetings .Where(m => m.ScoId == null && m.OfficeHoursId.HasValue) .Select(s => s.OfficeHoursId.Value) .Distinct(); if (OfficeHoursMeetingIds.Any()) { var officeHours = _dbContext.OfficeHours.Where(oh => OfficeHoursMeetingIds.Contains(oh.OfficeHoursId)); foreach (var officeHour in officeHours) { var meetings = filtredMeetings.Where(m => m.OfficeHoursId == officeHour.OfficeHoursId); foreach (var meeting in meetings) { meeting.ScoId = officeHour.ScoId; } } } IEnumerable <MeetingDto> result = filtredMeetings.Select( f => new MeetingDto { MeetingScoId = f.ScoId, Name = f.MeetingNameInfo.meetingName } ); return(result.ToSuccessResult()); }
public static async Task <ApiException> CreateApiException(this HttpResponseMessage response, IJsonDeserializer jsonDeserializer) { if (response == null) { throw new ArgumentNullException(nameof(response)); } if (jsonDeserializer == null) { throw new ArgumentNullException(nameof(jsonDeserializer)); } var httpErrorObject = await response.Content.ReadAsStringAsync(); try { ApiError deserializedErrorObject = jsonDeserializer.JsonDeserialize <ApiError>(httpErrorObject); // Now wrap into an exception which best fullfills the needs of your application: //ApiException ex = (deserializedErrorObject != null) // ? new ApiException(deserializedErrorObject.ToString(), response, deserializedErrorObject) // : new ApiException(response, deserializedErrorObject); string responseUri = response.RequestMessage.RequestUri.ToString(); ApiException ex = ((deserializedErrorObject != null) && !string.IsNullOrWhiteSpace(deserializedErrorObject.message)) ? new ApiException(deserializedErrorObject.message + "." + deserializedErrorObject.exceptionMessage, response, deserializedErrorObject) : new ApiException(responseUri, response, deserializedErrorObject); // Sometimes, there may be Model Errors: if (deserializedErrorObject.modelState != null) { var errors = deserializedErrorObject.modelState .Select(kvp => string.Join(". ", kvp.Value)); for (int i = 0; i < errors.Count(); i++) { // Wrap the errors up into the base Exception.Data Dictionary: ex.Data.Add(i, errors.ElementAt(i)); } } // Othertimes, there may not be Model Errors: //else //{ // var error = // JsonConvert.DeserializeObject<Dictionary<string, string>>(httpErrorObject); // foreach (var kvp in error) // { // // Wrap the errors up into the base Exception.Data Dictionary: // ex.Data.Add(kvp.Key, kvp.Value); // } //} return(ex); } catch (Exception ex) { throw new InvalidOperationException(string.Format("Can't parse {0} to exception.", httpErrorObject), ex); } }
public string UpdateName(LmsCourseMeeting meeting, string lmsMeetingTitle) { if (meeting == null) { throw new ArgumentNullException(nameof(meeting)); } if (string.IsNullOrWhiteSpace(lmsMeetingTitle)) { throw new ArgumentException("Meeting Title is required", nameof(lmsMeetingTitle)); } MeetingNameInfo nameInfo = _nameInfoDeserializer.JsonDeserialize <MeetingNameInfo>(meeting.MeetingNameJson); nameInfo.meetingName = lmsMeetingTitle; meeting.MeetingNameJson = _nameInfoSerializer.JsonSerialize(nameInfo); return(lmsMeetingTitle.TruncateIfMoreThen(60)); }
public string UpdateName(LmsCourseMeeting meeting, string lmsMeetingTitle) { if (meeting == null) { throw new ArgumentNullException(nameof(meeting)); } if (string.IsNullOrWhiteSpace(lmsMeetingTitle)) { throw new ArgumentException("Meeting Title is required", nameof(lmsMeetingTitle)); } MeetingNameInfo nameInfo = _nameInfoDeserializer.JsonDeserialize <MeetingNameInfo>(meeting.MeetingNameJson); nameInfo.meetingName = lmsMeetingTitle; meeting.MeetingNameJson = _nameInfoSerializer.JsonSerialize(nameInfo); if (meeting.LmsMeetingType == (int)LmsMeetingType.OfficeHours) { return(lmsMeetingTitle.TruncateIfMoreThen(60)); } return(string.Format("{0}: {1}", (string)nameInfo.courseNum, lmsMeetingTitle).TruncateIfMoreThen(60)); }