public async Task <ActionResult> GetTimeLineItem(TimeLineItemViewModel model) { string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail); string id = model.ItemId.ToString(); int type = model.TypeId; int itemId; bool idParse = int.TryParse(id, out itemId); if (type == (int)KinaUnaTypes.TimeLineType.Photo) { if (idParse) { PictureViewModel picture = await _mediaHttpClient.GetPictureViewModel(itemId, 0, 1, userinfo.Timezone); if (picture != null) { if (!picture.PictureLink.StartsWith("https://")) { picture.PictureLink = _imageStore.UriFor(picture.PictureLink); } picture.CommentsCount = picture.CommentsList.Count; return(PartialView("TimeLinePhotoPartial", picture)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Video) { if (idParse) { VideoViewModel video = await _mediaHttpClient.GetVideoViewModel(itemId, 0, 1, userinfo.Timezone); if (video != null) { video.CommentsCount = video.CommentsList.Count; return(PartialView("TimeLineVideoPartial", video)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Calendar) { if (idParse) { CalendarItem evt = await _progenyHttpClient.GetCalendarItem(itemId); // _context.CalendarDb.AsNoTracking().SingleOrDefault(e => e.EventId == itemId); if (evt != null && evt.StartTime.HasValue && evt.EndTime.HasValue) { evt.StartTime = TimeZoneInfo.ConvertTimeFromUtc(evt.StartTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); evt.EndTime = TimeZoneInfo.ConvertTimeFromUtc(evt.EndTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); return(PartialView("TimeLineEventPartial", evt)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Vocabulary) { if (idParse) { VocabularyItem voc = await _progenyHttpClient.GetWord(itemId); // _context.VocabularyDb.AsNoTracking().SingleOrDefault(v => v.WordId == itemId); if (voc != null) { if (voc.Date != null) { voc.Date = TimeZoneInfo.ConvertTimeFromUtc(voc.Date.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); } return(PartialView("TimeLineVocabularyPartial", voc)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Skill) { if (idParse) { Skill skl = await _progenyHttpClient.GetSkill(itemId); // _context.SkillsDb.AsNoTracking().SingleOrDefault(s => s.SkillId == itemId); if (skl != null) { return(PartialView("TimeLineSkillPartial", skl)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Friend) { if (idParse) { Friend frn = await _progenyHttpClient.GetFriend(itemId); // _context.FriendsDb.AsNoTracking().SingleOrDefault(f => f.FriendId == itemId); if (frn != null) { if (!frn.PictureLink.StartsWith("https://")) { frn.PictureLink = _imageStore.UriFor(frn.PictureLink, "friends"); } return(PartialView("TimeLineFriendPartial", frn)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Measurement) { if (idParse) { Measurement mes = await _progenyHttpClient.GetMeasurement(itemId); // _context.MeasurementsDb.AsNoTracking().SingleOrDefault(m => m.MeasurementId == itemId); if (mes != null) { return(PartialView("TimeLineMeasurementPartial", mes)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Sleep) { if (idParse) { Sleep slp = await _progenyHttpClient.GetSleepItem(itemId); // _context.SleepDb.AsNoTracking().SingleOrDefault(s => s.SleepId == itemId); if (slp != null) { slp.SleepStart = TimeZoneInfo.ConvertTimeFromUtc(slp.SleepStart, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); slp.SleepEnd = TimeZoneInfo.ConvertTimeFromUtc(slp.SleepEnd, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); DateTimeOffset sOffset = new DateTimeOffset(slp.SleepStart, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone).GetUtcOffset(slp.SleepStart)); DateTimeOffset eOffset = new DateTimeOffset(slp.SleepEnd, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone).GetUtcOffset(slp.SleepEnd)); slp.SleepDuration = eOffset - sOffset; return(PartialView("TimeLineSleepPartial", slp)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Note) { if (idParse) { Note nte = await _progenyHttpClient.GetNote(itemId); // _context.NotesDb.AsNoTracking().SingleOrDefault(n => n.NoteId == itemId); if (nte != null) { nte.CreatedDate = TimeZoneInfo.ConvertTimeFromUtc(nte.CreatedDate, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); return(PartialView("TimeLineNotePartial", nte)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Contact) { if (idParse) { Contact cnt = await _progenyHttpClient.GetContact(itemId); // _context.ContactsDb.AsNoTracking().SingleOrDefault(c => c.ContactId == itemId); if (cnt != null) { if (!cnt.PictureLink.StartsWith("https://")) { cnt.PictureLink = _imageStore.UriFor(cnt.PictureLink, "contacts"); } if (cnt.DateAdded == null) { cnt.DateAdded = new DateTime(1900, 1, 1); } return(PartialView("TimeLineContactPartial", cnt)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Vaccination) { if (idParse) { Vaccination vac = await _progenyHttpClient.GetVaccination(itemId); // _context.VaccinationsDb.AsNoTracking().SingleOrDefault(v => v.VaccinationId == itemId); if (vac != null) { return(PartialView("TimeLineVaccinationPartial", vac)); } } } if (type == (int)KinaUnaTypes.TimeLineType.Location) { if (idParse) { Location loc = await _progenyHttpClient.GetLocation(itemId); // _context.LocationsDb.AsNoTracking().SingleOrDefault(l => l.LocationId == itemId); if (loc != null) { return(PartialView("TimeLineLocationPartial", loc)); } } } Note failNote = new Note(); failNote.CreatedDate = DateTime.UtcNow; failNote.Title = "Error, content not found."; return(PartialView("TimeLineNotePartial", failNote)); }
public async Task <IActionResult> Video(int id, int childId = 0, string tagFilter = "", int sortBy = 1) { _progId = childId; string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; string userTimeZone = HttpContext.User.FindFirst("timezone")?.Value ?? Constants.DefaultTimezone; if (string.IsNullOrEmpty(userTimeZone)) { userTimeZone = Constants.DefaultTimezone; } UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail); if (childId == 0 && userinfo.ViewChild > 0) { _progId = userinfo.ViewChild; } Progeny progeny = await _progenyHttpClient.GetProgeny(_progId); List <UserAccess> accessList = await _progenyHttpClient.GetProgenyAccessList(_progId); int userAccessLevel = (int)AccessLevel.Public; if (accessList.Count != 0) { UserAccess userAccess = accessList.SingleOrDefault(u => u.UserId.ToUpper() == userEmail.ToUpper()); if (userAccess != null) { userAccessLevel = userAccess.AccessLevel; } } if (progeny.IsInAdminList(userEmail)) { _userIsProgenyAdmin = true; userAccessLevel = (int)AccessLevel.Private; } VideoViewModel video = await _mediaHttpClient.GetVideoViewModel(id, userAccessLevel, sortBy, userinfo.Timezone); VideoViewModel model = new VideoViewModel(); model.VideoId = video.VideoId; model.VideoType = video.VideoType; model.VideoTime = video.VideoTime; model.ProgenyId = video.ProgenyId; model.Progeny = progeny; model.Owners = video.Owners; model.VideoLink = video.VideoLink; model.ThumbLink = video.ThumbLink; model.AccessLevel = video.AccessLevel; model.Author = video.Author; model.AccessLevelListEn[video.AccessLevel].Selected = true; model.AccessLevelListDa[video.AccessLevel].Selected = true; model.AccessLevelListDe[video.AccessLevel].Selected = true; model.CommentThreadNumber = video.CommentThreadNumber; model.Tags = video.Tags; model.TagsList = video.TagsList; model.Location = video.Location; model.Latitude = video.Latitude; model.Longtitude = video.Longtitude; model.Altitude = video.Altitude; model.VideoNumber = video.VideoNumber; model.VideoCount = video.VideoCount; model.PrevVideo = video.PrevVideo; model.NextVideo = video.NextVideo; model.CommentsList = video.CommentsList; model.CommentsCount = video.CommentsList?.Count ?? 0; model.TagFilter = tagFilter; model.SortBy = sortBy; model.UserId = HttpContext.User.FindFirst("sub")?.Value ?? _defaultUser; model.IsAdmin = _userIsProgenyAdmin; if (video.Duration != null) { model.DurationHours = video.Duration.Value.Hours.ToString(); model.DurationMinutes = video.Duration.Value.Minutes.ToString(); model.DurationSeconds = video.Duration.Value.Seconds.ToString(); } if (model.VideoTime != null && progeny.BirthDay.HasValue) { PictureTime picTime = new PictureTime(progeny.BirthDay.Value, TimeZoneInfo.ConvertTimeToUtc(model.VideoTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userTimeZone)), TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone)); model.VidTimeValid = true; model.VidTime = model.VideoTime.Value.ToString("dd MMMM yyyy HH:mm"); // Todo: Replace string format with global constant or user defined value model.VidYears = picTime.CalcYears(); model.VidMonths = picTime.CalcMonths(); model.VidWeeks = picTime.CalcWeeks(); model.VidDays = picTime.CalcDays(); model.VidHours = picTime.CalcHours(); model.VidMinutes = picTime.CalcMinutes(); } else { model.VidTimeValid = false; model.VidTime = ""; } if (model.CommentsCount > 0) { foreach (Comment cmnt in model.CommentsList) { UserInfo cmntAuthor = await _progenyHttpClient.GetUserInfoByUserId(cmnt.Author); string authorImg = cmntAuthor?.ProfilePicture ?? ""; string authorName = ""; if (!String.IsNullOrEmpty(authorImg)) { if (!authorImg.ToLower().StartsWith("http")) { authorImg = _imageStore.UriFor(authorImg, "profiles"); } } else { authorImg = "/photodb/profile.jpg"; } cmnt.AuthorImage = authorImg; if (!String.IsNullOrEmpty(cmntAuthor.FirstName)) { authorName = cmntAuthor.FirstName; } if (!String.IsNullOrEmpty(cmntAuthor.MiddleName)) { authorName = authorName + " " + cmntAuthor.MiddleName; } if (!String.IsNullOrEmpty(cmntAuthor.LastName)) { authorName = authorName + " " + cmntAuthor.LastName; } authorName = authorName.Trim(); if (String.IsNullOrEmpty(authorName)) { authorName = cmntAuthor.UserName; if (String.IsNullOrEmpty(authorName)) { authorName = cmnt.DisplayName; } } cmnt.DisplayName = authorName; } } if (model.IsAdmin) { model.ProgenyLocations = new List <Location>(); model.ProgenyLocations = await _progenyHttpClient.GetProgenyLocations(model.ProgenyId, userAccessLevel); model.LocationsList = new List <SelectListItem>(); if (model.ProgenyLocations.Any()) { foreach (Location loc in model.ProgenyLocations) { SelectListItem selectListItem = new SelectListItem(); selectListItem.Text = loc.Name; selectListItem.Value = loc.LocationId.ToString(); model.LocationsList.Add(selectListItem); } } } return(View(model)); }