public async Task <IActionResult> DeleteProgeny(Progeny model) { string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail); Progeny prog = await _progenyHttpClient.GetProgeny(model.Id); if (!prog.IsInAdminList(userinfo.UserEmail)) { // Todo: Show no access info. return(RedirectToAction("Index")); } List <Picture> photoList = await _mediaHttpClient.GetPictureList(model.Id, (int)AccessLevel.Private, userinfo.Timezone); if (photoList.Any()) { foreach (Picture picture in photoList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == picture.PictureId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Photo); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } await _mediaHttpClient.DeletePicture(picture.PictureId); } } List <Video> videoList = await _mediaHttpClient.GetVideoList(model.Id, 0, userinfo.Timezone); if (videoList.Any()) { foreach (Video video in videoList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == video.VideoId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Video); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } await _mediaHttpClient.DeleteVideo(video.VideoId); } } List <CalendarItem> eventsList = _context.CalendarDb.Where(e => e.ProgenyId == model.Id).ToList(); if (eventsList.Any()) { foreach (CalendarItem evt in eventsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == evt.EventId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Calendar); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.CalendarDb.Remove(evt); await _context.SaveChangesAsync(); } } List <VocabularyItem> vocabList = _context.VocabularyDb.Where(v => v.ProgenyId == model.Id).ToList(); if (vocabList.Any()) { foreach (VocabularyItem voc in vocabList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == voc.WordId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Vocabulary); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.VocabularyDb.Remove(voc); await _context.SaveChangesAsync(); } } List <Skill> skillList = _context.SkillsDb.Where(s => s.ProgenyId == model.Id).ToList(); if (skillList.Any()) { foreach (Skill skill in skillList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == skill.SkillId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Skill); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.SkillsDb.Remove(skill); await _context.SaveChangesAsync(); } } List <Friend> friendsList = _context.FriendsDb.Where(f => f.ProgenyId == model.Id).ToList(); if (friendsList.Any()) { foreach (Friend friend in friendsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == friend.FriendId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Friend); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } if (!friend.PictureLink.ToLower().StartsWith("http")) { await _imageStore.DeleteImage(friend.PictureLink); } _context.FriendsDb.Remove(friend); await _context.SaveChangesAsync(); } } List <Measurement> measurementsList = _context.MeasurementsDb.Where(m => m.ProgenyId == model.Id).ToList(); if (measurementsList.Any()) { foreach (Measurement measurement in measurementsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == measurement.MeasurementId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Measurement); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.MeasurementsDb.Remove(measurement); await _context.SaveChangesAsync(); } } List <Sleep> sleepList = _context.SleepDb.Where(s => s.ProgenyId == model.Id).ToList(); if (sleepList.Any()) { foreach (Sleep sleep in sleepList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == sleep.SleepId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Sleep); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.SleepDb.Remove(sleep); await _context.SaveChangesAsync(); } } List <Note> notesList = _context.NotesDb.Where(n => n.ProgenyId == model.Id).ToList(); if (notesList.Any()) { foreach (Note note in notesList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == note.NoteId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Note); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } // Todo: Delete content add from notes _context.NotesDb.Remove(note); await _context.SaveChangesAsync(); } } List <Contact> contactsList = _context.ContactsDb.Where(c => c.ProgenyId == model.Id).ToList(); if (contactsList.Any()) { foreach (Contact contact in contactsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == contact.ContactId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Contact); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.ContactsDb.Remove(contact); if (contact.AddressIdNumber != null) { Address address = await _context.AddressDb.SingleAsync(a => a.AddressId == contact.AddressIdNumber); _context.AddressDb.Remove(address); } await _context.SaveChangesAsync(); if (!contact.PictureLink.ToLower().StartsWith("http")) { await _imageStore.DeleteImage(contact.PictureLink); } } } List <Vaccination> vaccinationsList = _context.VaccinationsDb.Where(v => v.ProgenyId == model.Id).ToList(); if (vaccinationsList.Any()) { foreach (Vaccination vaccination in vaccinationsList) { TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == vaccination.VaccinationId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Vaccination); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); } _context.VaccinationsDb.Remove(vaccination); await _context.SaveChangesAsync(); } } await _progenyHttpClient.DeleteProgeny(model.Id); return(RedirectToAction("Index")); }
public async Task <IActionResult> PhotoLocations(int childId = 0, string tagFilter = "") { _progId = childId; string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; 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; } LocationViewModel model = new LocationViewModel(); model.LocationsList = new List <Location>(); List <string> tagsList = new List <string>(); model.ProgenyId = _progId; model.Progeny = progeny; List <Picture> pictures = await _mediaHttpClient.GetPictureList(progeny.Id, userAccessLevel, userinfo.Timezone); if (String.IsNullOrEmpty(tagFilter)) { pictures = pictures.FindAll(p => !string.IsNullOrEmpty(p.Longtitude)); } else { pictures = pictures.FindAll(p => !string.IsNullOrEmpty(p.Longtitude) && p.Tags != null && p.Tags.ToUpper().Contains(tagFilter.ToUpper())); } pictures = pictures.OrderBy(p => p.PictureTime).ToList(); List <Picture> locPictures = new List <Picture>(); foreach (Picture pic in pictures) { Location picLoc = new Location(); bool validCoords = true; double lat; if (double.TryParse(pic.Latitude, NumberStyles.AllowDecimalPoint, new CultureInfo("en-US"), out lat)) { picLoc.Latitude = lat; } else { validCoords = false; } double lon; if (double.TryParse(pic.Longtitude, NumberStyles.AllowDecimalPoint, new CultureInfo("en-US"), out lon)) { picLoc.Longitude = lon; } else { validCoords = false; } if (validCoords && (pic.AccessLevel == (int)AccessLevel.Public || pic.AccessLevel >= userAccessLevel)) { picLoc.LocationId = pic.PictureId; model.LocationsList.Add(picLoc); locPictures.Add(pic); } } if (model.LocationsList.Any()) { foreach (Picture locPic in locPictures) { if (!String.IsNullOrEmpty(locPic.Tags)) { List <string> locTags = locPic.Tags.Split(',').ToList(); foreach (string tagstring in locTags) { if (!tagsList.Contains(tagstring.TrimStart(' ', ',').TrimEnd(' ', ','))) { tagsList.Add(tagstring.TrimStart(' ', ',').TrimEnd(' ', ',')); } } } } } string tags = ""; foreach (string tstr in tagsList) { tags = tags + tstr + ","; } model.Tags = tags.TrimEnd(','); model.TagFilter = tagFilter; return(View(model)); }