public async Task <IActionResult> SendConfirmationMail(string UserId, string NewEmail, string OldEmail, string Language) { if (User.Identity.IsAuthenticated) { ApplicationUser user = await _context.Users.SingleOrDefaultAsync(u => u.Id == UserId); ApplicationUser test = await _context.Users.SingleOrDefaultAsync(u => u.Email.ToUpper() == NewEmail.ToUpper()); if (user.Id == UserId) { if (test != null) { ChangeEmailViewModel model = new ChangeEmailViewModel(); model.OldEmail = OldEmail; model.NewEmail = NewEmail; string errorMsg = "Error: This email is already in use by another account. Please delete the account with this email address before assigning this email address to your account."; if (Language == "da") { errorMsg = "Fejl: Denne emailadresse er allerede i brug for en anden konto. Slet venligst den anden konto før du opdaterer denne konto med emailaddressen."; } if (Language == "de") { errorMsg = "Fehler: E-Mail wird von einem anderen Konto verwendet."; } model.ErrorMessage = errorMsg; model.UserId = user.Id; return(View("ChangeEmail", model)); } var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailUpdateConfirmationAsync(NewEmail, callbackUrl + "&newEmail=" + NewEmail + "&oldEmail=" + OldEmail, Language); UserInfo userinfo = await _progContext.UserInfoDb.SingleOrDefaultAsync(u => u.UserId == user.Id); if (userinfo != null) { userinfo.UserEmail = NewEmail; _progContext.UserInfoDb.Update(userinfo); await _progContext.SaveChangesAsync(); } user.Email = NewEmail; _context.Users.Update(user); await _context.SaveChangesAsync(); return(RedirectToAction("VerificationMailSent")); } } return(RedirectToAction("Register")); }
public async Task <IActionResult> Post([FromBody] UserInfo value) { UserInfo userinfo = new UserInfo(); userinfo.ViewChild = value?.ViewChild ?? 0; userinfo.UserEmail = value?.UserEmail ?? ""; userinfo.UserId = value?.UserId ?? ""; userinfo.Timezone = value?.Timezone ?? "Central European Standard Time"; userinfo.FirstName = value?.FirstName ?? ""; userinfo.MiddleName = value?.MiddleName ?? ""; userinfo.LastName = value?.LastName ?? ""; userinfo.ProfilePicture = value?.ProfilePicture ?? ""; userinfo.UserName = value?.UserName ?? userinfo.UserEmail; string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (userEmail.ToUpper() != userinfo.UserEmail.ToUpper()) { return(Unauthorized()); } _context.UserInfoDb.Add(userinfo); await _context.SaveChangesAsync(); userinfo.AccessList = await _context.UserAccessDb.Where(u => u.UserId.ToUpper() == userinfo.UserEmail.ToUpper()).ToListAsync(); userinfo.ProgenyList = new List <Progeny>(); if (userinfo.AccessList.Any()) { foreach (UserAccess ua in userinfo.AccessList) { Progeny progeny = await _context.ProgenyDb.SingleOrDefaultAsync(p => p.Id == ua.ProgenyId); userinfo.ProgenyList.Add(progeny); if (ua.AccessLevel == 0 || ua.CanContribute) { userinfo.CanUserAddItems = true; } } } await _dataService.SetUserInfoByEmail(userinfo.UserEmail); return(Ok(userinfo)); }
public async Task <IActionResult> Post([FromBody] Address value) { Address addressItem = new Address(); addressItem.AddressLine1 = value.AddressLine1; addressItem.AddressLine2 = value.AddressLine2; addressItem.City = value.City; addressItem.Country = value.Country; addressItem.PostalCode = value.PostalCode; addressItem.State = value.State; _context.AddressDb.Add(addressItem); await _context.SaveChangesAsync(); await _dataService.SetAddressItem(addressItem.AddressId); return(Ok(addressItem)); }
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 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] TimeLineItem value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add timeline items for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } TimeLineItem timeLineItem = new TimeLineItem(); timeLineItem.ProgenyId = value.ProgenyId; timeLineItem.AccessLevel = value.AccessLevel; timeLineItem.CreatedBy = value.CreatedBy; timeLineItem.CreatedTime = value.CreatedTime; timeLineItem.ItemId = value.ItemId; timeLineItem.ItemType = value.ItemType; timeLineItem.ProgenyTime = value.ProgenyTime; _context.TimeLineDb.Add(timeLineItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(timeLineItem.TimeLineId); return(Ok(timeLineItem)); }
public async Task <IActionResult> Put(int id, [FromBody] MobileNotification value) { string userId = User.GetUserId(); if (string.IsNullOrEmpty(userId)) { return(Unauthorized()); } MobileNotification mobileNotification = _context.MobileNotificationsDb.SingleOrDefault(m => m.NotificationId == id); if (mobileNotification != null && mobileNotification.UserId == userId) { mobileNotification.Read = value.Read; _context.MobileNotificationsDb.Update(mobileNotification); await _context.SaveChangesAsync(); return(Ok(mobileNotification)); } return(Ok(value)); }
public async Task ProgenyUpdateNotification(string title, string message, TimeLineItem timeLineItem, string iconLink = "") { var payload = new JObject( new JProperty("data", new JObject(new JProperty("title", title), new JProperty("message", message))), new JProperty("notData", timeLineItem.TimeLineId)); List <UserAccess> userList = await _dataService.GetProgenyUserAccessList(timeLineItem.ProgenyId); foreach (UserAccess userAcces in userList) { if (userAcces.AccessLevel <= timeLineItem.AccessLevel) { UserInfo userInfo = await _dataService.GetUserInfoByEmail(userAcces.UserId); if (userInfo != null) { MobileNotification notification = new MobileNotification(); notification.UserId = userInfo.UserId; notification.IconLink = iconLink; notification.ItemId = timeLineItem.ItemId; notification.ItemType = timeLineItem.ItemType; notification.Language = "EN"; notification.Message = message; notification.Title = title; notification.Time = DateTime.UtcNow; notification.Read = false; _context.MobileNotificationsDb.Add(notification); await _context.SaveChangesAsync(); string userTag = "userEmail:" + userAcces.UserId.ToUpper(); await Hub.SendFcmNativeNotificationAsync(payload.ToString(Newtonsoft.Json.Formatting.None), userTag); } } } // Android }
public async Task <IActionResult> Post([FromBody] Vaccination value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add vaccinations for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Vaccination vaccinationItem = new Vaccination(); vaccinationItem.AccessLevel = value.AccessLevel; vaccinationItem.Author = value.Author; vaccinationItem.Notes = value.Notes; vaccinationItem.VaccinationDate = value.VaccinationDate; vaccinationItem.ProgenyId = value.ProgenyId; vaccinationItem.VaccinationDescription = value.VaccinationDescription; vaccinationItem.VaccinationName = value.VaccinationName; _context.VaccinationsDb.Add(vaccinationItem); await _context.SaveChangesAsync(); await _dataService.SetVaccination(vaccinationItem.VaccinationId); TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = vaccinationItem.ProgenyId; tItem.AccessLevel = vaccinationItem.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Vaccination; tItem.ItemId = vaccinationItem.VaccinationId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); if (userinfo != null) { tItem.CreatedBy = userinfo.UserId; } tItem.CreatedTime = DateTime.UtcNow; tItem.ProgenyTime = vaccinationItem.VaccinationDate; await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); string title = "Vaccination added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new vaccination for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(vaccinationItem)); }
public async Task <IActionResult> Post([FromBody] Friend value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add contacts for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Friend friendItem = new Friend(); friendItem.AccessLevel = value.AccessLevel; friendItem.Author = value.Author; friendItem.Context = value.Context; friendItem.Name = value.Name; friendItem.Type = value.Type; friendItem.FriendAddedDate = DateTime.UtcNow; friendItem.ProgenyId = value.ProgenyId; friendItem.Description = value.Description; friendItem.FriendSince = value.FriendSince; friendItem.Notes = value.Notes; friendItem.PictureLink = value.PictureLink; friendItem.Tags = value.Tags; _context.FriendsDb.Add(friendItem); await _context.SaveChangesAsync(); await _dataService.SetFriend(friendItem.FriendId); // Add item to Timeline. TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = friendItem.ProgenyId; tItem.AccessLevel = friendItem.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Friend; tItem.ItemId = friendItem.FriendId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); tItem.CreatedBy = userinfo?.UserId ?? "User Not Found"; tItem.CreatedTime = DateTime.UtcNow; if (friendItem.FriendSince != null) { tItem.ProgenyTime = friendItem.FriendSince.Value; } else { tItem.ProgenyTime = DateTime.UtcNow; } await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); string title = "Friend added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new friend for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(friendItem)); }
public async Task <IActionResult> Post([FromBody] Measurement value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add measurements for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Measurement measurementItem = new Measurement(); measurementItem.AccessLevel = value.AccessLevel; measurementItem.Author = value.Author; measurementItem.Date = value.Date; measurementItem.Circumference = value.Circumference; measurementItem.ProgenyId = value.ProgenyId; measurementItem.EyeColor = value.EyeColor; measurementItem.CreatedDate = DateTime.UtcNow; measurementItem.HairColor = value.HairColor; measurementItem.Height = value.Height; measurementItem.Weight = value.Weight; _context.MeasurementsDb.Add(measurementItem); await _context.SaveChangesAsync(); await _dataService.SetMeasurement(measurementItem.MeasurementId); TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = measurementItem.ProgenyId; tItem.AccessLevel = measurementItem.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Measurement; tItem.ItemId = measurementItem.MeasurementId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); tItem.CreatedBy = userinfo?.UserId ?? "Unknown"; tItem.CreatedTime = DateTime.UtcNow; tItem.ProgenyTime = measurementItem.Date; await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); string title = "Measurement added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new measurement for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(measurementItem)); }
public async Task <IActionResult> Post([FromBody] CalendarItem value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add calendar items for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } CalendarItem calendarItem = new CalendarItem(); calendarItem.AccessLevel = value.AccessLevel; calendarItem.Author = value.Author; calendarItem.Notes = value.Notes; calendarItem.ProgenyId = value.ProgenyId; calendarItem.AllDay = value.AllDay; calendarItem.Context = value.Context; calendarItem.Location = value.Location; calendarItem.Title = value.Title; calendarItem.StartTime = value.StartTime; calendarItem.EndTime = value.EndTime; _context.CalendarDb.Add(calendarItem); await _context.SaveChangesAsync(); TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = calendarItem.ProgenyId; tItem.AccessLevel = calendarItem.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Calendar; tItem.ItemId = calendarItem.EventId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); tItem.CreatedBy = userinfo?.UserId ?? "User not found"; tItem.CreatedTime = DateTime.UtcNow; if (calendarItem.StartTime != null) { tItem.ProgenyTime = calendarItem.StartTime.Value; } else { tItem.ProgenyTime = DateTime.UtcNow; } await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); await _dataService.SetCalendarItem(calendarItem.EventId); string title = "Calendar item added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new calendar item for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(calendarItem)); }
public async Task <IActionResult> Post([FromBody] Note value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add notes for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Note noteItem = new Note(); noteItem.AccessLevel = value.AccessLevel; noteItem.Owner = value.Owner; noteItem.Content = value.Content; noteItem.Category = value.Category; noteItem.ProgenyId = value.ProgenyId; noteItem.Title = value.Title; noteItem.CreatedDate = value?.CreatedDate ?? DateTime.UtcNow; _context.NotesDb.Add(noteItem); await _context.SaveChangesAsync(); await _dataService.SetNote(noteItem.NoteId); // Add to Timeline. TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = noteItem.ProgenyId; tItem.AccessLevel = noteItem.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Note; tItem.ItemId = noteItem.NoteId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); if (userinfo != null) { tItem.CreatedBy = userinfo.UserId; } tItem.CreatedTime = noteItem.CreatedDate; tItem.ProgenyTime = noteItem.CreatedDate; await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); string title = "Note added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new note for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(noteItem)); }
public async Task <IActionResult> Post([FromBody] Sleep value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail(); if (prog != null) { // Check if user is allowed to add sleep for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Sleep sleepItem = new Sleep(); sleepItem.AccessLevel = value.AccessLevel; sleepItem.Author = value.Author; sleepItem.SleepNotes = value.SleepNotes; sleepItem.SleepRating = value.SleepRating; sleepItem.ProgenyId = value.ProgenyId; sleepItem.SleepStart = value.SleepStart; sleepItem.SleepEnd = value.SleepEnd; sleepItem.CreatedDate = DateTime.UtcNow; _context.SleepDb.Add(sleepItem); await _context.SaveChangesAsync(); await _dataService.SetSleep(sleepItem.SleepId); TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = sleepItem.ProgenyId; tItem.AccessLevel = sleepItem.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Sleep; tItem.ItemId = sleepItem.SleepId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); tItem.CreatedBy = userinfo?.UserId ?? "Unknown"; tItem.CreatedTime = DateTime.UtcNow; tItem.ProgenyTime = sleepItem.SleepStart; await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); string title = "Sleep added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new sleep item for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(sleepItem)); }
public async Task <IActionResult> Post([FromBody] UserAccess value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); if (prog != null) { // Check if user is allowed to add users for this child. string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } UserAccess userAccess = new UserAccess(); userAccess.ProgenyId = value.ProgenyId; userAccess.AccessLevel = value.AccessLevel; userAccess.UserId = value.UserId; userAccess.CanContribute = value.CanContribute; // If a UserAccess entry with the same user and progeny exists, replace it. var progenyAccessList = await _context.UserAccessDb.Where(u => u.UserId.ToUpper() == userAccess.UserId.ToUpper()).ToListAsync(); var oldUserAccess = progenyAccessList.SingleOrDefault(u => u.ProgenyId == userAccess.ProgenyId); if (oldUserAccess != null) { _context.UserAccessDb.Remove(oldUserAccess); await _context.SaveChangesAsync(); await _dataService.RemoveUserAccess(oldUserAccess.AccessId, oldUserAccess.ProgenyId, oldUserAccess.UserId); } _context.UserAccessDb.Add(userAccess); await _context.SaveChangesAsync(); Progeny progeny = await _dataService.GetProgeny(userAccess.ProgenyId); if (userAccess.AccessLevel == (int)AccessLevel.Private && !progeny.IsInAdminList(userAccess.UserId)) { progeny.Admins = progeny.Admins + ", " + userAccess.UserId.ToUpper(); await _dataService.UpdateProgenyAdmins(progeny); } if (userAccess.AccessLevel == (int)AccessLevel.Private) { await _dataService.SetProgenyUserIsAdmin(userAccess.UserId); } await _dataService.SetProgenyUserAccessList(userAccess.ProgenyId); await _dataService.SetUsersUserAccessList(userAccess.UserId); await _dataService.SetUserAccess(userAccess.AccessId); string title = "User added for " + prog.NickName; UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == User.GetEmail().ToUpper()); string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added 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(Ok(userAccess)); }
public async Task <IActionResult> Post([FromBody] Contact value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add contacts for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Contact contactItem = new Contact(); contactItem.AccessLevel = value.AccessLevel; contactItem.Active = value.Active; contactItem.AddressString = value.AddressString; contactItem.ProgenyId = value.ProgenyId; contactItem.Author = value.Author; contactItem.DateAdded = value?.DateAdded ?? DateTime.UtcNow; contactItem.Context = value.Context; contactItem.DisplayName = value.DisplayName; contactItem.Email1 = value.Email1; contactItem.Email2 = value.Email2; contactItem.FirstName = value.FirstName; contactItem.LastName = value.LastName; contactItem.MiddleName = value.MiddleName; contactItem.MobileNumber = value.MobileNumber; contactItem.Notes = value.Notes; contactItem.PhoneNumber = value.PhoneNumber; if (value.PictureLink != "[KeepExistingLink]") { contactItem.PictureLink = value.PictureLink; } contactItem.Tags = value.Tags; contactItem.Website = value.Website; contactItem.Address = value.Address; if (contactItem.Address != null) { if (contactItem.Address.AddressLine1 + contactItem.Address.AddressLine2 + contactItem.Address.City + contactItem.Address.Country + contactItem.Address.PostalCode + contactItem.Address.State != "") { Address address = new Address(); address.AddressLine1 = contactItem.Address.AddressLine1; address.AddressLine2 = contactItem.Address.AddressLine2; address.City = contactItem.Address.City; address.PostalCode = contactItem.Address.PostalCode; address.State = contactItem.Address.State; address.Country = contactItem.Address.Country; await _context.AddressDb.AddAsync(address); await _context.SaveChangesAsync(); contactItem.AddressIdNumber = address.AddressId; } } _context.ContactsDb.Add(contactItem); await _context.SaveChangesAsync(); await _dataService.SetContact(contactItem.ContactId); TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = contactItem.ProgenyId; tItem.AccessLevel = contactItem.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Contact; tItem.ItemId = contactItem.ContactId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); tItem.CreatedBy = userinfo?.UserId ?? "User not found"; tItem.CreatedTime = DateTime.UtcNow; tItem.ProgenyTime = contactItem.DateAdded.Value; await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); string title = "Contact added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new contact for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(contactItem)); }
public async Task <IActionResult> Post([FromBody] Location value) { // Check if child exists. Progeny prog = await _context.ProgenyDb.AsNoTracking().SingleOrDefaultAsync(p => p.Id == value.ProgenyId); string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail; if (prog != null) { // Check if user is allowed to add locations for this child. if (!prog.IsInAdminList(userEmail)) { return(Unauthorized()); } } else { return(NotFound()); } Location location = new Location(); location.AccessLevel = value.AccessLevel; location.Author = value.Author; location.City = value.City; location.Country = value.Country; location.County = value.County; location.Date = value.Date; location.DateAdded = value.DateAdded; location.District = value.District; location.HouseNumber = value.HouseNumber; location.Latitude = value.Latitude; location.Longitude = value.Longitude; location.Name = value.Name; location.Notes = value.Notes; location.PostalCode = value.PostalCode; location.ProgenyId = value.ProgenyId; location.State = value.State; location.StreetName = value.StreetName; location.Tags = value.Tags; _context.LocationsDb.Add(location); await _context.SaveChangesAsync(); await _dataService.SetLocation(location.LocationId); TimeLineItem tItem = new TimeLineItem(); tItem.ProgenyId = location.ProgenyId; tItem.AccessLevel = location.AccessLevel; tItem.ItemType = (int)KinaUnaTypes.TimeLineType.Location; tItem.ItemId = location.LocationId.ToString(); UserInfo userinfo = _context.UserInfoDb.SingleOrDefault(u => u.UserEmail.ToUpper() == userEmail.ToUpper()); if (userinfo != null) { tItem.CreatedBy = userinfo.UserId; } tItem.CreatedTime = DateTime.UtcNow; if (location.Date.HasValue) { tItem.ProgenyTime = location.Date.Value; } else { tItem.ProgenyTime = DateTime.UtcNow; } await _context.TimeLineDb.AddAsync(tItem); await _context.SaveChangesAsync(); await _dataService.SetTimeLineItem(tItem.TimeLineId); string title = "Location added for " + prog.NickName; string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " added a new location for " + prog.NickName; await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture); return(Ok(location)); }