public void OnProgenyKilled() { if (!IsOnShip && Progeny.All(progeny => !progeny.IsOnShip)) { SetThreatStatus(ThreatStatus.Defeated, true); } }
public async Task <IActionResult> AdminListByUser(string id) { string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (userEmail.ToUpper() == id.ToUpper()) { List <UserAccess> userAccessList = await _dataService.GetUsersUserAccessList(id); userAccessList = userAccessList.Where(u => u.AccessLevel == 0).ToList(); List <Progeny> progenyList = new List <Progeny>(); if (userAccessList.Any()) { foreach (UserAccess ua in userAccessList) { Progeny progeny = await _dataService.GetProgeny(ua.ProgenyId); progenyList.Add(progeny); } if (progenyList.Any()) { return(Ok(progenyList)); } return(Ok()); } } return(Ok()); }
public async Task <IActionResult> AddProgeny(ProgenyViewModel model) { Progeny prog = new Progeny(); prog.BirthDay = model.BirthDay; prog.Admins = model.Admins.ToUpper(); prog.Name = model.Name; prog.NickName = model.NickName; prog.PictureLink = model.PictureLink; prog.TimeZone = model.TimeZone; // Todo: Check if the progeny exists. if (model.File != null) { using (var stream = model.File.OpenReadStream()) { prog.PictureLink = await _imageStore.SaveImage(stream, "progeny"); } } else { prog.PictureLink = Constants.WebAppUrl + "/photodb/childcareicon.jpg"; // Todo: Find better image } await _progenyHttpClient.AddProgeny(prog); return(RedirectToAction("Index")); }
public async Task <IActionResult> Delete(int id) { TimeLineItem timeLineItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.TimeLineId == id); if (timeLineItem != null) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == timeLineItem.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to delete timeline items for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } _context.TimeLineDb.Remove(timeLineItem); await _context.SaveChangesAsync(); await _dataService.RemoveTimeLineItem(timeLineItem.TimeLineId, timeLineItem.ItemType, timeLineItem.ProgenyId); return(NoContent()); } return(NotFound()); }
private void ProgenyCollectionView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { _myChildrenViewModel.EditMode = false; EditButton.Text = IconFont.AccountEdit; Progeny prog = (Progeny)ProgenyCollectionView.SelectedItem; if (prog != null) { _myChildrenViewModel.Progeny = (Progeny)ProgenyCollectionView.SelectedItem; ProgenyCollectionView.ScrollTo(ProgenyCollectionView.SelectedItem); //if (_myChildrenViewModel.Progeny.BirthDay.HasValue) //{ // BirthdayDatePicker.Date = _myChildrenViewModel.Progeny.BirthDay.Value.Date; // BirthdayTimePicker.Time = _myChildrenViewModel.Progeny.BirthDay.Value.TimeOfDay; //} TimeZoneInfo progenyTimeZoneInfo = _myChildrenViewModel.TimeZoneList.SingleOrDefault(tz => tz.DisplayName == _myChildrenViewModel.Progeny.TimeZone); if (progenyTimeZoneInfo == null) { progenyTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(_myChildrenViewModel.Progeny.TimeZone); } _myChildrenViewModel.SelectedTimeZone = progenyTimeZoneInfo; ChildPicture.Source = _myChildrenViewModel.ProfilePicture; _selectedProgenyId = _myChildrenViewModel.Progeny.Id; } _filePath = ""; MessageLabel.Text = ""; MessageLabel.IsVisible = false; }
public async Task <IActionResult> Delete(int id) { UserAccess userAccess = await _context.UserAccessDb.SingleOrDefaultAsync(u => u.AccessId == id); if (userAccess != null) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == userAccess.ProgenyId); if (prog != null) { // Check if user is allowed to delete users for this child. string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Progeny progeny = await _dataService.GetProgeny(userAccess.ProgenyId); if (userAccess.AccessLevel == (int)AccessLevel.Private && progeny.IsInAdminList(userAccess.UserId)) { string[] adminList = progeny.Admins.Split(','); progeny.Admins = ""; foreach (string adminItem in adminList) { if (!adminItem.Trim().ToUpper().Equals(userAccess.UserId.Trim().ToUpper())) { progeny.Admins = progeny.Admins + ", " + userAccess.UserId.ToUpper(); } } progeny.Admins = progeny.Admins.Trim(','); await _dataService.UpdateProgenyAdmins(progeny); } _context.UserAccessDb.Remove(userAccess); await _context.SaveChangesAsync(); await _dataService.RemoveUserAccess(userAccess.AccessId, userAccess.ProgenyId, userAccess.UserId); string title = "User removed for " + prog.NickName; UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == User.GetEmail().ToUpper()); string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " removed user: " + userAccess.UserId; TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = userAccess.ProgenyId; tItem.AccessLevel = 0; tItem.ItemId = userAccess.AccessId.ToString(); tItem.ItemType = (int)KinaUnaTypes.TimeLineType.UserAccess; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(NoContent()); } return(NotFound()); }
public async Task <IActionResult> ProgenyListByUserMobile(string id) { string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (userEmail.ToUpper() == id.ToUpper()) { List <Progeny> result = new List <Progeny>(); List <UserAccess> userAccessList = await _dataService.GetUsersUserAccessList(id); if (userAccessList.Any()) { foreach (UserAccess ua in userAccessList) { Progeny prog = await _dataService.GetProgeny(ua.ProgenyId); if (!prog.PictureLink.ToLower().StartsWith("http")) { prog.PictureLink = _imageStore.UriFor(prog.PictureLink, "progeny"); } result.Add(prog); } return(Ok(result)); } } return(NotFound()); }
public async Task <IActionResult> Post([FromBody] Progeny value) { Progeny progeny = new Progeny(); progeny.Name = value.Name; progeny.NickName = value.NickName; progeny.BirthDay = value.BirthDay; progeny.TimeZone = value.TimeZone; progeny.Admins = value.Admins; progeny.PictureLink = value.PictureLink; _context.ProgenyDb.Add(progeny); await _context.SaveChangesAsync(); await _dataService.SetProgeny(progeny.Id); if (progeny.Admins.Contains(',')) { List <string> adminList = progeny.Admins.Split(',').ToList(); foreach (string adminEmail in adminList) { UserAccess ua = new UserAccess(); ua.AccessLevel = 0; ua.ProgenyId = progeny.Id; ua.UserId = adminEmail.Trim(); if (ua.UserId.IsValidEmail()) { _context.UserAccessDb.Add(ua); await _context.SaveChangesAsync(); await _dataService.SetProgenyUserIsAdmin(ua.UserId); await _dataService.SetProgenyUserAccessList(progeny.Id); await _dataService.SetUsersUserAccessList(ua.UserId); } } } else { UserAccess ua = new UserAccess(); ua.AccessLevel = 0; ua.ProgenyId = progeny.Id; ua.UserId = progeny.Admins.Trim(); if (ua.UserId.IsValidEmail()) { _context.UserAccessDb.Add(ua); await _context.SaveChangesAsync(); await _dataService.SetProgenyUserIsAdmin(ua.UserId); await _dataService.SetProgenyUserAccessList(progeny.Id); await _dataService.SetUsersUserAccessList(ua.UserId); } } return(Ok(progeny)); }
public async Task <IActionResult> ProgenyListByUser(string id) { List <Progeny> result = new List <Progeny>(); Progeny prog = await _dataService.GetProgeny(Constants.DefaultChildId); // _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == Constants.DefaultChildId); result.Add(prog); return(Ok(result)); }
public async Task <IActionResult> Delete(int id) { Location location = await _context.LocationsDb.SingleOrDefaultAsync(l => l.LocationId == id); if (location != null) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == location.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to delete locations for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == location.LocationId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Location); if (tItem != null) { if (location.Date.HasValue) { tItem.ProgenyTime = location.Date.Value; } tItem.AccessLevel = location.AccessLevel; _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); await _dataService.RemoveTimeLineItem(tItem.TimeLineId, tItem.ItemType, tItem.ProgenyId); } _context.LocationsDb.Remove(location); await _context.SaveChangesAsync(); await _dataService.RemoveLocation(location.LocationId, location.ProgenyId); UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail); string title = "Location deleted for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " deleted a location for " + prog.NickName + ". Location: " + location.Name; tItem.AccessLevel = 0; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(NoContent()); } return(NotFound()); }
private async void ProgenyCollectionView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { Progeny viewProgeny = ProgenyCollectionView.SelectedItem as Progeny; if (viewProgeny != null) { _viewModel.CategoryAutoSuggestList = await ProgenyService.GetCategoryAutoSuggestList(viewProgeny.Id, 0); } }
public async Task <IActionResult> ViewEvent(int eventId) { CalendarItem eventItem = await _progenyHttpClient.GetCalendarItem(eventId); // _context.CalendarDb.AsNoTracking().SingleAsync(e => e.EventId == eventId); CalendarItemViewModel model = new CalendarItemViewModel(); string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail); Progeny progeny = await _progenyHttpClient.GetProgeny(eventItem.ProgenyId); List <UserAccess> accessList = await _progenyHttpClient.GetProgenyAccessList(eventItem.ProgenyId); 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; } if (eventItem.AccessLevel < userAccessLevel) { // Todo: Show access denied instead of redirecting. RedirectToAction("Index"); } model.EventId = eventItem.EventId; model.ProgenyId = eventItem.ProgenyId; model.Progeny = progeny; model.Title = eventItem.Title; model.AllDay = eventItem.AllDay; if (eventItem.StartTime.HasValue && eventItem.EndTime.HasValue) { model.StartTime = TimeZoneInfo.ConvertTimeFromUtc(eventItem.StartTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); model.EndTime = TimeZoneInfo.ConvertTimeFromUtc(eventItem.EndTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); } model.Notes = eventItem.Notes; model.Location = eventItem.Location; model.Context = eventItem.Context; model.AccessLevel = eventItem.AccessLevel; model.IsAdmin = _userIsProgenyAdmin; return(View(model)); }
public MyChildrenViewModel() { LoginCommand = new Command(Login); ProgenyCollection = new ObservableCollection <Progeny>(); ProgenyAdminCollection = new ObservableCollection <Progeny>(); TimeZoneList = new ObservableCollection <TimeZoneInfo>(); _progeny = OfflineDefaultData.DefaultProgeny; _progenyBirthDay = new DateTime(2018, 02, 18, 18, 02, 00); }
public async Task <IActionResult> Delete(int id) { // Todo: Implement confirmation mail to verify that all content really should be deleted. Progeny progeny = await _context.ProgenyDb.SingleOrDefaultAsync(p => p.Id == id); if (progeny != null) { // Check if user is allowed to edit this child. string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (!progeny.IsInAdminList(userEmail)) { return(Unauthorized()); } // Todo: Delete content associated with progeny. // Todo: Delete TimeLine // Todo: Delete Pictures // Todo: Delete Videos // Todo: Delete Calendar // Todo: Delete Locations // Todo: Delete Vocabulary // Todo: Delete Skills // Todo: Delete Friends // Todo: Delete Measurements // Todo: Delete Sleep // Todo: Delete Notes // Todo: Delete Contacts // Todo: Delete Vaccinations if (!progeny.PictureLink.ToLower().StartsWith("http") && !String.IsNullOrEmpty(progeny.PictureLink)) { await _imageStore.DeleteImage(progeny.PictureLink, BlobContainers.Progeny); } List <UserAccess> userAccessList = _context.UserAccessDb.Where(ua => ua.ProgenyId == progeny.Id).ToList(); if (userAccessList.Any()) { foreach (UserAccess ua in userAccessList) { _context.UserAccessDb.Remove(ua); _context.SaveChanges(); await _dataService.RemoveUserAccess(ua.AccessId, ua.ProgenyId, ua.UserId); } } _context.ProgenyDb.Remove(progeny); await _context.SaveChangesAsync(); await _dataService.RemoveProgeny(id); return(NoContent()); } else { return(NotFound()); } }
protected override async void OnAppearing() { base.OnAppearing(); Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged; var networkAccess = Connectivity.NetworkAccess; bool internetAccess = networkAccess == NetworkAccess.Internet; if (internetAccess) { _viewModel.Online = true; OfflineStackLayout.IsVisible = false; } else { _viewModel.Online = false; OfflineStackLayout.IsVisible = true; } await ProgenyService.GetProgenyList(await UserService.GetUserEmail()); List <Progeny> progenyList = await ProgenyService.GetProgenyAdminList(); if (progenyList.Any()) { foreach (Progeny progeny in progenyList) { _viewModel.ProgenyCollection.Add(progeny); } string userviewchild = await SecureStorage.GetAsync(Constants.UserViewChildKey); bool viewchildParsed = int.TryParse(userviewchild, out int viewChild); Progeny viewProgeny = new Progeny(); if (viewchildParsed) { viewProgeny = _viewModel.ProgenyCollection.SingleOrDefault(p => p.Id == viewChild); } if (viewProgeny != null) { ProgenyCollectionView.SelectedItem = _viewModel.ProgenyCollection.SingleOrDefault(p => p.Id == viewChild); ProgenyCollectionView.ScrollTo(ProgenyCollectionView.SelectedItem); _viewModel.ContextAutoSuggestList = await ProgenyService.GetContextAutoSuggestList(viewProgeny.Id, 0); _viewModel.TagsAutoSuggestList = await ProgenyService.GetTagsAutoSuggestList(viewProgeny.Id, 0); } else { ProgenyCollectionView.SelectedItem = _viewModel.ProgenyCollection[0]; } } _viewModel.FriendType = 0; _viewModel.AccessLevel = 0; }
protected override async void OnAppearing() { base.OnAppearing(); await ProgenyService.GetProgenyList(await UserService.GetUserEmail()); List <Progeny> progenyList = await ProgenyService.GetProgenyAdminList(); if (progenyList.Any()) { foreach (Progeny progeny in progenyList) { _addSleepViewModel.ProgenyCollection.Add(progeny); } string userviewchild = await SecureStorage.GetAsync(Constants.UserViewChildKey); bool viewchildParsed = int.TryParse(userviewchild, out int viewChild); Progeny viewProgeny = new Progeny(); if (viewchildParsed) { viewProgeny = _addSleepViewModel.ProgenyCollection.SingleOrDefault(p => p.Id == viewChild); } if (viewProgeny != null) { ProgenyCollectionView.SelectedItem = _addSleepViewModel.ProgenyCollection.SingleOrDefault(p => p.Id == viewChild); ProgenyCollectionView.ScrollTo(ProgenyCollectionView.SelectedItem); } else { ProgenyCollectionView.SelectedItem = _addSleepViewModel.ProgenyCollection[0]; } } _addSleepViewModel.SleepItem.ProgenyId = ((Progeny)ProgenyCollectionView.SelectedItem).Id; _addSleepViewModel.SleepItem.SleepStart = DateTime.Now; _addSleepViewModel.SleepItem.SleepEnd = DateTime.Now + TimeSpan.FromMinutes(10); _addSleepViewModel.SleepItem.AccessLevel = 0; _addSleepViewModel.SleepItem.SleepRating = 3; _addSleepViewModel.StartYear = _addSleepViewModel.SleepItem.SleepStart.Year; _addSleepViewModel.StartMonth = _addSleepViewModel.SleepItem.SleepStart.Month; _addSleepViewModel.StartDay = _addSleepViewModel.SleepItem.SleepStart.Day; _addSleepViewModel.StartHours = _addSleepViewModel.SleepItem.SleepStart.Hour; _addSleepViewModel.StartMinutes = _addSleepViewModel.SleepItem.SleepStart.Minute; _addSleepViewModel.EndYear = _addSleepViewModel.SleepItem.SleepEnd.Year; _addSleepViewModel.EndMonth = _addSleepViewModel.SleepItem.SleepEnd.Month; _addSleepViewModel.EndDay = _addSleepViewModel.SleepItem.SleepEnd.Day; _addSleepViewModel.EndHours = _addSleepViewModel.SleepItem.SleepEnd.Hour; _addSleepViewModel.EndMinutes = _addSleepViewModel.SleepItem.SleepEnd.Minute; SleepStartTimePicker.Time = new TimeSpan(_addSleepViewModel.SleepItem.SleepStart.Hour, _addSleepViewModel.SleepItem.SleepStart.Minute, 0); SleepEndTimePicker.Time = new TimeSpan(_addSleepViewModel.SleepItem.SleepEnd.Hour, _addSleepViewModel.SleepItem.SleepEnd.Minute, 0); //CheckDates(); }
public async Task <IActionResult> Get() { Progeny prog = await _dataService.GetProgeny(Constants.DefaultChildId); List <Progeny> resultList = new List <Progeny>(); //_context.ProgenyDb.AsNoTracking().Where(p => p.Id == Constants.DefaultChildId).ToListAsync(); resultList.Add(prog); return(Ok(resultList)); }
public async Task <IActionResult> GetProgeny(int id) { Progeny result = await _dataService.GetProgeny(Constants.DefaultChildId); // _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == Constants.DefaultChildId); if (!result.PictureLink.ToLower().StartsWith("http")) { result.PictureLink = _imageStore.UriFor(result.PictureLink, BlobContainers.Progeny); } return(Ok(result)); }
public async Task <IActionResult> Delete(int id) { CalendarItem calendarItem = await _context.CalendarDb.SingleOrDefaultAsync(c => c.EventId == id); if (calendarItem != null) { string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; // Check if child exists. Progeny prog = await _context.ProgenyDb.SingleOrDefaultAsync(p => p.Id == calendarItem.ProgenyId); if (prog != null) { // Check if user is allowed to edit calendar items for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == calendarItem.EventId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Calendar); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); await _dataService.RemoveTimeLineItem(tItem.TimeLineId, tItem.ItemType, tItem.ProgenyId); } _context.CalendarDb.Remove(calendarItem); await _context.SaveChangesAsync(); await _dataService.RemoveCalendarItem(calendarItem.EventId, calendarItem.ProgenyId); UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail); string title = "Calendar item deleted for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " deleted a calendar item for " + prog.NickName; tItem.AccessLevel = 0; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(NoContent()); } else { return(NotFound()); } }
public async Task <IActionResult> Index(int childId = 0, int sortBy = 1, int items = 0) { _progId = childId; ViewBag.SortBy = sortBy; string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail); if (childId == 0 && userinfo.ViewChild > 0) { _progId = userinfo.ViewChild; } if (_progId == 0) { _progId = Constants.DefaultChildId; } 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)) { userAccessLevel = (int)AccessLevel.Private; } TimeLineViewModel model = new TimeLineViewModel(); model.TimeLineItems = new List <TimeLineItem>(); model.TimeLineItems = await _progenyHttpClient.GetTimeline(_progId, userAccessLevel); // _context.TimeLineDb.AsNoTracking().Where(t => t.ProgenyId == _progId && t.AccessLevel >= userAccessLevel && t.ProgenyTime < DateTime.UtcNow).ToListAsync(); if (sortBy == 1) { model.TimeLineItems = model.TimeLineItems.OrderByDescending(t => t.ProgenyTime).ToList(); } else { model.TimeLineItems = model.TimeLineItems.OrderBy(t => t.ProgenyTime).ToList(); } ViewBag.ProgenyName = progeny.NickName; ViewBag.Items = items; return(View(model)); }
public async Task <Progeny> CurrentChildAsync(int progenyId, string userId) { var currentContext = _httpContextAccessor.HttpContext; string accessToken = await currentContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken).ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(accessToken)) { _httpClient.SetBearerToken(accessToken); } else { accessToken = await GetNewToken(); _httpClient.SetBearerToken(accessToken); } string progenyApiPath = "/api/progeny/" + progenyId; var progenyResponseString = await _httpClient.GetStringAsync(progenyApiPath); Progeny child = JsonConvert.DeserializeObject <Progeny>(progenyResponseString); bool hasAccess = false; string accessApiPath = "/api/access/progeny/" + progenyId; var accessResponseString = await _httpClient.GetStringAsync(accessApiPath); List <UserAccess> accessList = JsonConvert.DeserializeObject <List <UserAccess> >(accessResponseString); if (accessList.Any()) { foreach (var accessItem in accessList) { if (accessItem.UserId.ToUpper() == userId.ToUpper()) { hasAccess = true; } } } if (child == null || !hasAccess) { if (child == null) { child = new Progeny(); } child.Name = "Test Child"; child.NickName = "Tester"; child.Id = -1; child.Admins = "*****@*****.**"; child.BirthDay = DateTime.Now; child.TimeZone = TimeZoneInfo.Utc.Id; child.PictureLink = "/images/images_placeholder.png"; } return(child); }
private async void ProgenyCollectionView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { Progeny viewProgeny = ProgenyCollectionView.SelectedItem as Progeny; if (viewProgeny != null) { _addPhotoViewModel.LocationAutoSuggestList = await ProgenyService.GetLocationAutoSuggestList(viewProgeny.Id, 0); _addPhotoViewModel.TagsAutoSuggestList = await ProgenyService.GetTagsAutoSuggestList(viewProgeny.Id, 0); } }
public async Task <IActionResult> Delete(int id) { Measurement measurementItem = await _context.MeasurementsDb.SingleOrDefaultAsync(m => m.MeasurementId == id); if (measurementItem != null) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == measurementItem.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to delete measurements for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == measurementItem.MeasurementId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Measurement); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); await _dataService.RemoveTimeLineItem(tItem.TimeLineId, tItem.ItemType, tItem.ProgenyId); } _context.MeasurementsDb.Remove(measurementItem); await _context.SaveChangesAsync(); await _dataService.RemoveMeasurement(measurementItem.MeasurementId, measurementItem.ProgenyId); UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail); string title = "Measurement deleted for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " deleted a measurement for " + prog.NickName + ". Measurement date: " + measurementItem.Date.Date.ToString("dd-MMM-yyyy"); tItem.AccessLevel = 0; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(NoContent()); } else { return(NotFound()); } }
public async Task <IActionResult> Delete(int id) { Sleep sleepItem = await _context.SleepDb.SingleOrDefaultAsync(s => s.SleepId == id); if (sleepItem != null) { string userEmail = User.GetEmail(); // Check if child exists. Progeny prog = await _context.ProgenyDb.SingleOrDefaultAsync(p => p.Id == sleepItem.ProgenyId); if (prog != null) { // Check if user is allowed to delete sleep for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.ItemId == sleepItem.SleepId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Sleep); if (tItem != null) { _context.TimeLineDb.Remove(tItem); await _context.SaveChangesAsync(); await _dataService.RemoveTimeLineItem(tItem.TimeLineId, tItem.ItemType, tItem.ProgenyId); } _context.SleepDb.Remove(sleepItem); await _context.SaveChangesAsync(); await _dataService.RemoveSleep(sleepItem.SleepId, sleepItem.ProgenyId); string title = "Sleep for " + prog.NickName + " deleted"; UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " deleted a sleep item for " + prog.NickName + ". Sleep start: " + sleepItem.SleepStart.ToString("dd-MMM-yyyy HH:mm"); await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(NoContent()); } else { return(NotFound()); } }
public async Task UpdateProgenyAdmins(Progeny progeny) { Progeny oldProgeny = await _context.ProgenyDb.SingleOrDefaultAsync(p => p.Id == progeny.Id); if (oldProgeny != null) { oldProgeny.Admins = progeny.Admins; _context.ProgenyDb.Update(oldProgeny); await _context.SaveChangesAsync(); await _cache.SetStringAsync(Constants.AppName + "progeny" + progeny.Id, JsonConvert.SerializeObject(oldProgeny), _cacheOptionsSliding); } }
public async Task <IActionResult> Post([FromBody] Video model) { // Check if user should be allowed access. string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; UserAccess userAccess = _progenyDbContext.UserAccessDb.SingleOrDefault(u => u.ProgenyId == model.ProgenyId && u.UserId.ToUpper() == userEmail.ToUpper()); if (userAccess == null || userAccess.AccessLevel > 0) { return(Unauthorized()); } Video vid = await _context.VideoDb.SingleOrDefaultAsync(v => v.VideoLink == model.VideoLink && v.ProgenyId == model.ProgenyId); if (vid == null) { CommentThread commentThread = new CommentThread(); await _context.CommentThreadsDb.AddAsync(commentThread); await _context.SaveChangesAsync(); model.CommentThreadNumber = commentThread.Id; await _context.VideoDb.AddAsync(model); await _context.SaveChangesAsync(); await _dataService.SetVideo(model.VideoId); Progeny prog = await _dataService.GetProgeny(model.ProgenyId); UserInfo userinfo = await _dataService.GetUserInfoByEmail(User.GetEmail()); string title = "New Video added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new video for " + prog.NickName; TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = model.ProgenyId; tItem.ItemId = model.VideoId.ToString(); tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Video; tItem.AccessLevel = model.AccessLevel; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(model)); } model = vid; return(Ok(model)); }
public HomeFeedViewModel() { LoginCommand = new Command(Login); ProgenyCollection = new ObservableCollection <Progeny>(); _latestPosts = new List <TimeLineItem>(); _timeLineItems = new ObservableRangeCollection <TimeLineItem>(); _progeny = OfflineDefaultData.DefaultProgeny; _imageId = OfflineDefaultData.DefaultPicture.PictureId; _imageLink = OfflineDefaultData.DefaultPicture.PictureLink; _imageLink600 = OfflineDefaultData.DefaultPicture.PictureLink600; ProgenyCollection.Add(OfflineDefaultData.DefaultProgeny); _tags = OfflineDefaultData.DefaultPicture.Tags; _userAccessLevel = 5; }
public NoteDetailViewModel() { _progeny = new Progeny(); _currentNote = new Note(); _currentNote.CreatedDate = DateTime.Now; _currentNote.AccessLevel = 0; _dateYear = _currentNote.CreatedDate.Year; _dateMonth = _currentNote.CreatedDate.Month; _dateDay = _currentNote.CreatedDate.Day; _dateHours = _currentNote.CreatedDate.Hour; _dateMinutes = _currentNote.CreatedDate.Minute; NoteItems = new ObservableRangeCollection <Note>(); _accessLevelList = new List <string>(); var ci = CrossMultilingual.Current.CurrentCultureInfo.TwoLetterISOLanguageName; if (ci == "da") { _accessLevelList.Add("Administratorer"); _accessLevelList.Add("Familie"); _accessLevelList.Add("Omsorgspersoner/Speciel adgang"); _accessLevelList.Add("Venner"); _accessLevelList.Add("Registrerede brugere"); _accessLevelList.Add("Offentlig/alle"); } else { if (ci == "de") { _accessLevelList.Add("Administratoren"); _accessLevelList.Add("Familie"); _accessLevelList.Add("Betreuer/Spezial"); _accessLevelList.Add("Freunde"); _accessLevelList.Add("Registrierte Benutzer"); _accessLevelList.Add("Allen zugänglich"); } else { _accessLevelList.Add("Hidden/Private"); _accessLevelList.Add("Family"); _accessLevelList.Add("Caretakers/Special Access"); _accessLevelList.Add("Friends"); _accessLevelList.Add("Registered Users"); _accessLevelList.Add("Public/Anyone"); } } }
public async Task <IActionResult> Put(int id, [FromBody] Video value) { Video video = await _context.VideoDb.SingleOrDefaultAsync(v => v.VideoId == id); // Todo: more validation of the values if (video == null) { return(NotFound()); } // Check if user should be allowed access. string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; UserAccess userAccess = _progenyDbContext.UserAccessDb.AsNoTracking().SingleOrDefault(u => u.ProgenyId == video.ProgenyId && u.UserId.ToUpper() == userEmail.ToUpper()); if (userAccess == null || userAccess.AccessLevel > 0) { return(Unauthorized()); } video.Tags = value.Tags; video.AccessLevel = value.AccessLevel; video.Author = value.Author; video.VideoTime = value.VideoTime; video.Duration = value.Duration; video.Location = value.Location; video.Longtitude = value.Longtitude; video.Latitude = value.Latitude; video.Altitude = value.Altitude; _context.VideoDb.Update(video); await _context.SaveChangesAsync(); await _dataService.SetVideo(video.VideoId); Progeny prog = await _dataService.GetProgeny(video.ProgenyId); UserInfo userinfo = await _dataService.GetUserInfoByEmail(User.GetEmail()); string title = "Video Edited for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " edited a video for " + prog.NickName; TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = video.ProgenyId; tItem.ItemId = video.VideoId.ToString(); tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Video; tItem.AccessLevel = video.AccessLevel; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(video)); }