Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        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());
            }
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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());
            }
        }
Exemplo n.º 8
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());
            }
        }
Exemplo n.º 9
0
        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());
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> DeleteProgeny(int progenyId)
        {
            string   userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser;
            UserInfo userinfo  = await _progenyHttpClient.GetUserInfo(userEmail);

            Progeny prog = await _progenyHttpClient.GetProgeny(progenyId);

            if (!prog.IsInAdminList(userinfo.UserEmail))
            {
                // Todo: Show no access info.
                return(RedirectToAction("Index"));
            }

            return(View(prog));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Put(int id, [FromBody] TimeLineItem value)
        {
            TimeLineItem timeLineItem = await _context.TimeLineDb.SingleOrDefaultAsync(t => t.TimeLineId == id);

            if (timeLineItem == null)
            {
                return(NotFound());
            }

            // 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 edit timeline items for this child.
                if (!prog.IsInAdminList(userEmail))
                {
                    return(Unauthorized());
                }
            }
            else
            {
                return(NotFound());
            }

            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.Update(timeLineItem);
            await _context.SaveChangesAsync();

            await _dataService.SetTimeLineItem(timeLineItem.TimeLineId);

            return(Ok(timeLineItem));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> EditProgeny(ProgenyViewModel model)
        {
            string   userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser;
            UserInfo userinfo  = await _progenyHttpClient.GetUserInfo(userEmail);

            Progeny prog = await _progenyHttpClient.GetProgeny(model.ProgenyId);

            if (!prog.IsInAdminList(userinfo.UserEmail))
            {
                // Todo: Show no access info.
                return(RedirectToAction("Index"));
            }

            prog.BirthDay = model.BirthDay;
            prog.Admins   = model.Admins.ToUpper();
            prog.Name     = model.Name;
            prog.NickName = model.NickName;
            prog.TimeZone = model.TimeZone;
            // Todo: check if fields are valid.

            if (model.File != null && model.File.Name != String.Empty)
            {
                string oldPictureLink = prog.PictureLink;
                using (var stream = model.File.OpenReadStream())
                {
                    prog.PictureLink = await _imageStore.SaveImage(stream, "progeny");
                }

                if (!oldPictureLink.ToLower().StartsWith("http") && !String.IsNullOrEmpty(oldPictureLink))
                {
                    await _imageStore.DeleteImage(oldPictureLink, "progeny");
                }
            }
            await _progenyHttpClient.UpdateProgeny(prog);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Put(int id, [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 edit measurements for this child.
                if (!prog.IsInAdminList(userEmail))
                {
                    return(Unauthorized());
                }
            }
            else
            {
                return(NotFound());
            }

            Measurement measurementItem = await _context.MeasurementsDb.SingleOrDefaultAsync(m => m.MeasurementId == id);

            if (measurementItem == null)
            {
                return(NotFound());
            }

            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.Update(measurementItem);
            await _context.SaveChangesAsync();

            await _dataService.SetMeasurement(measurementItem.MeasurementId);

            TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t =>
                                                                                t.ItemId == measurementItem.MeasurementId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Measurement);

            if (tItem != null)
            {
                tItem.ProgenyTime = measurementItem.Date;
                tItem.AccessLevel = measurementItem.AccessLevel;
                _context.TimeLineDb.Update(tItem);
                await _context.SaveChangesAsync();

                await _dataService.SetTimeLineItem(tItem.TimeLineId);
            }

            UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail);

            string title   = "Measurement edited for " + prog.NickName;
            string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " edited a measurement for " + prog.NickName;
            await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture);

            return(Ok(measurementItem));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Index(int childId = 0)
        {
            _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;
            }
            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))
            {
                _userIsProgenyAdmin = true;
                userAccessLevel     = (int)AccessLevel.Private;
            }

            VaccinationViewModel model = new VaccinationViewModel();

            model.VaccinationList = new List <Vaccination>();
            List <Vaccination> vaccinations = await _progenyHttpClient.GetVaccinationsList(_progId, userAccessLevel); // _context.VaccinationsDb.AsNoTracking().Where(v => v.ProgenyId == _progId).ToList();

            if (vaccinations.Count != 0)
            {
                foreach (Vaccination v in vaccinations)
                {
                    if (v.AccessLevel >= userAccessLevel)
                    {
                        model.VaccinationList.Add(v);
                    }
                }
                model.VaccinationList = model.VaccinationList.OrderBy(v => v.VaccinationDate).ToList();
            }
            else
            {
                Vaccination vaccination = new Vaccination();
                vaccination.ProgenyId              = _progId;
                vaccination.VaccinationName        = "No vaccinations found.";
                vaccination.VaccinationDescription = "The vaccinations list is empty.";

                model.VaccinationList.Add(vaccination);
            }
            model.IsAdmin = _userIsProgenyAdmin;
            model.Progeny = progeny;
            return(View(model));
        }
Exemplo n.º 18
0
        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"));
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Put(int id, [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 edit notes for this child.
                if (!prog.IsInAdminList(userEmail))
                {
                    return(Unauthorized());
                }
            }
            else
            {
                return(NotFound());
            }

            Note noteItem = await _context.NotesDb.SingleOrDefaultAsync(n => n.NoteId == id);

            if (noteItem == null)
            {
                return(NotFound());
            }

            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;

            _context.NotesDb.Update(noteItem);
            await _context.SaveChangesAsync();

            await _dataService.SetNote(noteItem.NoteId);

            // Update Timeline.
            TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t =>
                                                                                t.ItemId == noteItem.NoteId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Note);

            if (tItem != null)
            {
                tItem.ProgenyTime = noteItem.CreatedDate;
                tItem.AccessLevel = noteItem.AccessLevel;
                _context.TimeLineDb.Update(tItem);
                await _context.SaveChangesAsync();

                await _dataService.SetTimeLineItem(tItem.TimeLineId);
            }

            UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail);

            string title   = "Note edited for " + prog.NickName;
            string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " edited a note for " + prog.NickName;
            await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture);

            return(Ok(noteItem));
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Index(int childId = 0)
        {
            _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;
            }
            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))
            {
                _userIsProgenyAdmin = true;
                userAccessLevel     = (int)AccessLevel.Private;
            }
            List <SkillViewModel> model = new List <SkillViewModel>();

            List <Skill> skillsList = await _progenyHttpClient.GetSkillsList(_progId, userAccessLevel); // _context.SkillsDb.Where(w => w.ProgenyId == _progId).ToList();

            skillsList = skillsList.OrderBy(s => s.SkillFirstObservation).ToList();
            if (skillsList.Count != 0)
            {
                foreach (Skill skill in skillsList)
                {
                    SkillViewModel skillViewModel = new SkillViewModel();
                    skillViewModel.ProgenyId             = skill.ProgenyId;
                    skillViewModel.AccessLevel           = skill.AccessLevel;
                    skillViewModel.Description           = skill.Description;
                    skillViewModel.Category              = skill.Category;
                    skillViewModel.Name                  = skill.Name;
                    skillViewModel.SkillFirstObservation = skill.SkillFirstObservation;
                    skillViewModel.SkillId               = skill.SkillId;
                    skillViewModel.IsAdmin               = _userIsProgenyAdmin;
                    if (skillViewModel.AccessLevel >= userAccessLevel)
                    {
                        model.Add(skillViewModel);
                    }
                }
            }
            else
            {
                SkillViewModel skillViewModel = new SkillViewModel();
                skillViewModel.ProgenyId             = _progId;
                skillViewModel.AccessLevel           = (int)AccessLevel.Public;
                skillViewModel.Description           = "The skills list is empty.";
                skillViewModel.Category              = "";
                skillViewModel.Name                  = "No items";
                skillViewModel.SkillFirstObservation = DateTime.UtcNow;

                skillViewModel.IsAdmin = _userIsProgenyAdmin;

                model.Add(skillViewModel);
            }

            model[0].Progeny = progeny;
            return(View(model));
        }
Exemplo n.º 21
0
        public async Task <IActionResult> Put(int id, [FromBody] Contact value)
        {
            Contact contactItem = await _context.ContactsDb.SingleOrDefaultAsync(c => c.ContactId == id);

            if (contactItem == null)
            {
                return(NotFound());
            }

            // 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 edit contacts for this child.

                if (!prog.IsInAdminList(userEmail))
                {
                    return(Unauthorized());
                }
            }
            else
            {
                return(NotFound());
            }

            contactItem.AccessLevel     = value.AccessLevel;
            contactItem.Active          = value.Active;
            contactItem.AddressIdNumber = value.AddressIdNumber;
            contactItem.AddressString   = value.AddressString;
            contactItem.ProgenyId       = value.ProgenyId;
            contactItem.Author          = value.Author;
            if (value.DateAdded.HasValue)
            {
                contactItem.DateAdded = value.DateAdded.Value.ToUniversalTime();
            }
            else
            {
                contactItem.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.AddressIdNumber != null && contactItem.AddressIdNumber.Value != 0)
            {
                Address addressOld = await _context.AddressDb.SingleAsync(c => c.AddressId == contactItem.AddressIdNumber);

                if (contactItem.Address != null)
                {
                    addressOld.AddressLine1 = contactItem.Address.AddressLine1;
                    addressOld.AddressLine2 = contactItem.Address.AddressLine2;
                    addressOld.City         = contactItem.Address.City;
                    addressOld.PostalCode   = contactItem.Address.PostalCode;
                    addressOld.State        = contactItem.Address.State;
                    addressOld.Country      = contactItem.Address.Country;
                    contactItem.Address     = addressOld;

                    _context.AddressDb.Update(addressOld);
                    await _dataService.SetAddressItem(addressOld.AddressId);
                }
                else
                {
                    int removedAddressId = addressOld.AddressId;
                    _context.AddressDb.Remove(addressOld);
                    contactItem.AddressIdNumber = null;
                    await _dataService.RemoveAddressItem(removedAddressId);
                }

                await _context.SaveChangesAsync();
            }
            else
            {
                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.Update(contactItem);
            await _context.SaveChangesAsync();

            await _dataService.SetContact(contactItem.ContactId);

            TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t =>
                                                                                t.ItemId == contactItem.ContactId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Contact);

            if (tItem != null)
            {
                tItem.ProgenyTime = contactItem.DateAdded.Value;
                tItem.AccessLevel = contactItem.AccessLevel;
                _context.TimeLineDb.Update(tItem);
                await _context.SaveChangesAsync();

                await _dataService.SetTimeLineItem(tItem.TimeLineId);
            }

            UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail);

            string title   = "Contact edited for " + prog.NickName;
            string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " edited a contact for " + prog.NickName;
            await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture);

            return(Ok(contactItem));
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Delete(int id)
        {
            Contact contactItem = await _context.ContactsDb.SingleOrDefaultAsync(c => c.ContactId == id);

            if (contactItem != null)
            {
                string userEmail = User.GetEmail() ?? Constants.DefaultUserEmail;
                // Check if child exists.
                Progeny prog = await _context.ProgenyDb.SingleOrDefaultAsync(p => p.Id == contactItem.ProgenyId);

                if (prog != null)
                {
                    // Check if user is allowed to delete contacts for this child.
                    if (!prog.IsInAdminList(userEmail))
                    {
                        return(Unauthorized());
                    }
                }
                else
                {
                    return(NotFound());
                }

                TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t =>
                                                                                    t.ItemId == contactItem.ContactId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Contact);

                if (tItem != null)
                {
                    _context.TimeLineDb.Remove(tItem);
                    await _context.SaveChangesAsync();

                    await _dataService.RemoveTimeLineItem(tItem.TimeLineId, tItem.ItemType, tItem.ProgenyId);
                }

                if (contactItem.AddressIdNumber != null)
                {
                    Address address = await _context.AddressDb.SingleAsync(a => a.AddressId == contactItem.AddressIdNumber);

                    _context.AddressDb.Remove(address);
                    await _dataService.RemoveAddressItem(address.AddressId);
                }
                if (!contactItem.PictureLink.ToLower().StartsWith("http"))
                {
                    await _imageStore.DeleteImage(contactItem.PictureLink, BlobContainers.Contacts);
                }

                _context.ContactsDb.Remove(contactItem);
                await _context.SaveChangesAsync();

                await _dataService.RemoveContact(contactItem.ContactId, contactItem.ProgenyId);

                UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail);

                string title   = "Contact deleted for " + prog.NickName;
                string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " deleted a contact for " + prog.NickName + ". Contact: " + contactItem.DisplayName;
                tItem.AccessLevel = 0;
                await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture);

                return(NoContent());
            }

            return(NotFound());
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Put(int id, [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 edit vaccinations for this child.
                if (!prog.IsInAdminList(userEmail))
                {
                    return(Unauthorized());
                }
            }
            else
            {
                return(NotFound());
            }

            Vaccination vaccinationItem = await _context.VaccinationsDb.SingleOrDefaultAsync(v => v.VaccinationId == id);

            if (vaccinationItem == null)
            {
                return(NotFound());
            }

            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.Update(vaccinationItem);
            await _context.SaveChangesAsync();

            await _dataService.SetVaccination(vaccinationItem.VaccinationId);

            TimeLineItem tItem = await _context.TimeLineDb.SingleOrDefaultAsync(t =>
                                                                                t.ItemId == vaccinationItem.VaccinationId.ToString() && t.ItemType == (int)KinaUnaTypes.TimeLineType.Vaccination);

            if (tItem != null)
            {
                tItem.ProgenyTime = vaccinationItem.VaccinationDate;
                tItem.AccessLevel = vaccinationItem.AccessLevel;
                _context.TimeLineDb.Update(tItem);
                await _context.SaveChangesAsync();

                await _dataService.SetTimeLineItem(tItem.TimeLineId);
            }

            UserInfo userinfo = await _dataService.GetUserInfoByEmail(userEmail);

            string title   = "Vaccination edited for " + prog.NickName;
            string message = userinfo.FirstName + " " + userinfo.MiddleName + " " + userinfo.LastName + " edited a vaccination for " + prog.NickName;
            await _azureNotifications.ProgenyUpdateNotification(title, message, tItem, userinfo.ProfilePicture);

            return(Ok(vaccinationItem));
        }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 25
0
        public async Task <IActionResult> Index(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;
            }

            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))
            {
                _userIsProgenyAdmin = true;
                userAccessLevel     = (int)AccessLevel.Private;
            }

            List <FriendViewModel> model = new List <FriendViewModel>();

            List <string> tagsList    = new List <string>();
            List <Friend> friendsList = await _progenyHttpClient.GetFriendsList(_progId, userAccessLevel); // _context.FriendsDb.AsNoTracking().Where(w => w.ProgenyId == _progId).ToList();

            if (!string.IsNullOrEmpty(tagFilter))
            {
                friendsList = friendsList.Where(c => c.Tags != null && c.Tags.ToUpper().Contains(tagFilter.ToUpper())).ToList();
                // friendsList = _context.FriendsDb.AsNoTracking().Where(f => f.ProgenyId == _progId && f.Tags.Contains(tagFilter)).ToList();
            }

            friendsList = friendsList.OrderBy(f => f.FriendSince).ToList();
            if (friendsList.Count != 0)
            {
                foreach (Friend friend in friendsList)
                {
                    FriendViewModel friendViewModel = new FriendViewModel();
                    friendViewModel.ProgenyId       = friend.ProgenyId;
                    friendViewModel.AccessLevel     = friend.AccessLevel;
                    friendViewModel.FriendAddedDate = friend.FriendAddedDate;
                    friendViewModel.FriendSince     = friend.FriendSince;
                    friendViewModel.Name            = friend.Name;
                    friendViewModel.Description     = friend.Description;
                    friendViewModel.IsAdmin         = _userIsProgenyAdmin;
                    friendViewModel.FriendId        = friend.FriendId;
                    friendViewModel.PictureLink     = friend.PictureLink;
                    friendViewModel.Type            = friend.Type;
                    friendViewModel.Context         = friend.Context;
                    friendViewModel.Notes           = friend.Notes;
                    friendViewModel.Tags            = friend.Tags;
                    if (!String.IsNullOrEmpty(friendViewModel.Tags))
                    {
                        List <string> pvmTags = friendViewModel.Tags.Split(',').ToList();
                        foreach (string tagstring in pvmTags)
                        {
                            if (!tagsList.Contains(tagstring.TrimStart(' ', ',').TrimEnd(' ', ',')))
                            {
                                tagsList.Add(tagstring.TrimStart(' ', ',').TrimEnd(' ', ','));
                            }
                        }
                    }
                    if (!friendViewModel.PictureLink.StartsWith("https://"))
                    {
                        friendViewModel.PictureLink = _imageStore.UriFor(friendViewModel.PictureLink, "friends");
                    }

                    if (friendViewModel.AccessLevel >= userAccessLevel)
                    {
                        model.Add(friendViewModel);
                    }
                }

                string tags = "";
                foreach (string tstr in tagsList)
                {
                    tags = tags + tstr + ",";
                }
                ViewBag.Tags = tags.TrimEnd(',');
            }
            else
            {
                FriendViewModel friendViewModel = new FriendViewModel();
                friendViewModel.ProgenyId       = _progId;
                friendViewModel.Name            = "No friends found.";
                friendViewModel.FriendAddedDate = DateTime.UtcNow;
                friendViewModel.FriendSince     = DateTime.UtcNow;
                friendViewModel.Description     = "The friends list is empty.";
                friendViewModel.IsAdmin         = _userIsProgenyAdmin;
                model.Add(friendViewModel);
            }

            model[0].Progeny  = progeny;
            ViewBag.TagFilter = tagFilter;
            return(View(model));
        }
Exemplo n.º 26
0
        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));
        }
Exemplo n.º 27
0
        public async Task <IActionResult> Index(int id = 0)
        {
            int    childId      = id;
            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 (User.Identity.IsAuthenticated)
            {
                if (childId == 0 && userinfo.ViewChild > 0)
                {
                    _progId = userinfo.ViewChild;
                }
            }
            else
            {
                _progId = Constants.DefaultChildId;
            }

            Progeny progeny = await _progenyHttpClient.GetProgeny(_progId);

            if (progeny.Name == "401")
            {
                var returnUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}";
                return(RedirectToAction("CheckOut", "Account", new { returnUrl }));
            }
            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;
            }

            if (progeny.BirthDay.HasValue)
            {
                progeny.BirthDay = DateTime.SpecifyKind(progeny.BirthDay.Value, DateTimeKind.Unspecified);
            }

            HomeFeedViewModel feedModel = new HomeFeedViewModel();

            feedModel.UserAccessLevel = (int)AccessLevel.Public;
            if (accessList.Count != 0)
            {
                UserAccess userAccess = accessList.SingleOrDefault(u => u.UserId.ToUpper() == userEmail.ToUpper());
                if (userAccess != null)
                {
                    feedModel.UserAccessLevel = userAccess.AccessLevel;
                }
                else
                {
                    ViewBag.OriginalProgeny = progeny;
                    progeny = await _progenyHttpClient.GetProgeny(Constants.DefaultChildId);
                }
            }
            if (progeny.IsInAdminList(userEmail))
            {
                feedModel.UserAccessLevel = (int)AccessLevel.Private;
            }

            BirthTime progBirthTime;

            if (!String.IsNullOrEmpty(progeny.NickName) && progeny.BirthDay.HasValue && feedModel.UserAccessLevel < (int)AccessLevel.Public)
            {
                progBirthTime = new BirthTime(progeny.BirthDay.Value,
                                              TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
            }
            else
            {
                progBirthTime = new BirthTime(new DateTime(2018, 02, 18, 18, 02, 00), TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
            }

            feedModel.CurrentTime      = progBirthTime.CurrentTime;
            feedModel.Years            = progBirthTime.CalcYears();
            feedModel.Months           = progBirthTime.CalcMonths();
            feedModel.Weeks            = progBirthTime.CalcWeeks();
            feedModel.Days             = progBirthTime.CalcDays();
            feedModel.Hours            = progBirthTime.CalcHours();
            feedModel.Minutes          = progBirthTime.CalcMinutes();
            feedModel.NextBirthday     = progBirthTime.CalcNextBirthday();
            feedModel.MinutesMileStone = progBirthTime.CalcMileStoneMinutes();
            feedModel.HoursMileStone   = progBirthTime.CalcMileStoneHours();
            feedModel.DaysMileStone    = progBirthTime.CalcMileStoneDays();
            feedModel.WeeksMileStone   = progBirthTime.CalcMileStoneWeeks();


            Picture tempPicture = new Picture();

            tempPicture.ProgenyId      = 0;
            tempPicture.Progeny        = progeny;
            tempPicture.AccessLevel    = (int)AccessLevel.Public;
            tempPicture.PictureLink600 = $"https://{Request.Host}{Request.PathBase}" + "/photodb/0/default_temp.jpg";
            tempPicture.ProgenyId      = progeny.Id;
            tempPicture.PictureTime    = new DateTime(2018, 9, 1, 12, 00, 00);

            Picture displayPicture = tempPicture;

            if (feedModel.UserAccessLevel < (int)AccessLevel.Public)
            {
                displayPicture = await _mediaHttpClient.GetRandomPicture(progeny.Id, feedModel.UserAccessLevel, userTimeZone);
            }
            PictureTime picTime = new PictureTime(new DateTime(2018, 02, 18, 20, 18, 00), new DateTime(2018, 02, 18, 20, 18, 00), TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));

            if (feedModel.UserAccessLevel == (int)AccessLevel.Public || displayPicture == null)
            {
                displayPicture = await _mediaHttpClient.GetRandomPicture(Constants.DefaultChildId, feedModel.UserAccessLevel, userTimeZone);

                if (!displayPicture.PictureLink600.StartsWith("https://"))
                {
                    displayPicture.PictureLink600 = _imageStore.UriFor(displayPicture.PictureLink600);
                }

                feedModel.ImageLink600 = displayPicture.PictureLink600;
                feedModel.ImageId      = displayPicture.PictureId;
                picTime                = new PictureTime(new DateTime(2018, 02, 18, 20, 18, 00), displayPicture.PictureTime, TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
                feedModel.Tags         = displayPicture.Tags;
                feedModel.Location     = displayPicture.Location;
                feedModel.PicTimeValid = false;
            }
            else
            {
                if (!displayPicture.PictureLink600.StartsWith("https://"))
                {
                    displayPicture.PictureLink600 = _imageStore.UriFor(displayPicture.PictureLink600);
                }

                feedModel.ImageLink600 = displayPicture.PictureLink600;
                feedModel.ImageId      = displayPicture.PictureId;
                if (displayPicture.PictureTime != null && progeny.BirthDay.HasValue)
                {
                    picTime = new PictureTime(progeny.BirthDay.Value,
                                              displayPicture.PictureTime,
                                              TimeZoneInfo.FindSystemTimeZoneById(progeny.TimeZone));
                    feedModel.PicTimeValid = true;
                }

                feedModel.Tags     = displayPicture.Tags;
                feedModel.Location = displayPicture.Location;
            }
            feedModel.PicTime    = picTime.PictureDateTime;
            feedModel.PicYears   = picTime.CalcYears();
            feedModel.PicMonths  = picTime.CalcMonths();
            feedModel.PicWeeks   = picTime.CalcWeeks();
            feedModel.PicDays    = picTime.CalcDays();
            feedModel.PicHours   = picTime.CalcHours();
            feedModel.PicMinutes = picTime.CalcMinutes();
            feedModel.Progeny    = progeny;
            feedModel.EventsList = new List <CalendarItem>();
            feedModel.EventsList = await _progenyHttpClient.GetUpcomingEvents(_progId, userAccessLevel);

            foreach (CalendarItem eventItem in feedModel.EventsList)
            {
                if (eventItem.StartTime.HasValue && eventItem.EndTime.HasValue)
                {
                    eventItem.StartTime = TimeZoneInfo.ConvertTimeFromUtc(eventItem.StartTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone));
                    eventItem.EndTime   = TimeZoneInfo.ConvertTimeFromUtc(eventItem.EndTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone));
                }
            }

            feedModel.LatestPosts = new TimeLineViewModel();
            feedModel.LatestPosts.TimeLineItems = new List <TimeLineItem>();
            feedModel.LatestPosts.TimeLineItems = await _progenyHttpClient.GetProgenyLatestPosts(_progId, userAccessLevel);

            if (feedModel.LatestPosts.TimeLineItems.Any())
            {
                feedModel.LatestPosts.TimeLineItems = feedModel.LatestPosts.TimeLineItems.OrderByDescending(t => t.ProgenyTime).Take(5).ToList();
            }

            feedModel.YearAgoPosts = new TimeLineViewModel();
            feedModel.YearAgoPosts.TimeLineItems = new List <TimeLineItem>();
            feedModel.YearAgoPosts.TimeLineItems = await _progenyHttpClient.GetProgenyYearAgo(_progId, userAccessLevel);

            if (feedModel.YearAgoPosts.TimeLineItems.Any())
            {
                feedModel.YearAgoPosts.TimeLineItems = feedModel.YearAgoPosts.TimeLineItems.OrderByDescending(t => t.ProgenyTime).ToList();
            }

            return(View(feedModel));
        }
Exemplo n.º 28
0
        public async Task <IActionResult> Index(int childId = 0)
        {
            _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;
            }
            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))
            {
                _userIsProgenyAdmin = true;
                userAccessLevel     = (int)AccessLevel.Private;
            }

            List <VocabularyItemViewModel> model    = new List <VocabularyItemViewModel>();
            List <VocabularyItem>          wordList = await _progenyHttpClient.GetWordsList(_progId, userAccessLevel); // _context.VocabularyDb.Where(w => w.ProgenyId == _progId).ToList();

            wordList = wordList.OrderBy(w => w.Date).ToList();
            if (wordList.Count != 0)
            {
                foreach (VocabularyItem vocabularyItem in wordList)
                {
                    if (vocabularyItem.AccessLevel >= userAccessLevel)
                    {
                        VocabularyItemViewModel vocabularyItemViewModel = new VocabularyItemViewModel();
                        vocabularyItemViewModel.ProgenyId   = vocabularyItem.ProgenyId;
                        vocabularyItemViewModel.Date        = vocabularyItem.Date;
                        vocabularyItemViewModel.DateAdded   = vocabularyItem.DateAdded;
                        vocabularyItemViewModel.Description = vocabularyItem.Description;
                        vocabularyItemViewModel.Language    = vocabularyItem.Language;
                        vocabularyItemViewModel.SoundsLike  = vocabularyItem.SoundsLike;
                        vocabularyItemViewModel.Word        = vocabularyItem.Word;
                        vocabularyItemViewModel.IsAdmin     = _userIsProgenyAdmin;
                        vocabularyItemViewModel.WordId      = vocabularyItem.WordId;
                        model.Add(vocabularyItemViewModel);
                    }
                }
            }
            else
            {
                VocabularyItemViewModel vocabularyItemViewModel = new VocabularyItemViewModel();
                vocabularyItemViewModel.ProgenyId   = _progId;
                vocabularyItemViewModel.Date        = DateTime.UtcNow;
                vocabularyItemViewModel.DateAdded   = DateTime.UtcNow;
                vocabularyItemViewModel.Description = "The vocabulary list is empty.";
                vocabularyItemViewModel.Language    = "English";
                vocabularyItemViewModel.SoundsLike  = "";
                vocabularyItemViewModel.Word        = "No words found.";
                vocabularyItemViewModel.IsAdmin     = _userIsProgenyAdmin;
                model.Add(vocabularyItemViewModel);
            }

            model[0].Progeny = progeny;

            List <WordDateCount> dateTimesList = new List <WordDateCount>();
            int wordCount = 0;

            foreach (VocabularyItemViewModel vocabularyItemViewModel in model)
            {
                wordCount++;
                if (vocabularyItemViewModel.Date != null)
                {
                    if (dateTimesList.SingleOrDefault(d => d.WordDate.Date == vocabularyItemViewModel.Date.Value.Date) == null)
                    {
                        WordDateCount newDate = new WordDateCount();
                        newDate.WordDate  = vocabularyItemViewModel.Date.Value.Date;
                        newDate.WordCount = wordCount;
                        dateTimesList.Add(newDate);
                    }
                    else
                    {
                        WordDateCount wrdDateCount = dateTimesList.SingleOrDefault(d => d.WordDate.Date == vocabularyItemViewModel.Date.Value.Date);
                        if (wrdDateCount != null)
                        {
                            wrdDateCount.WordCount = wordCount;
                        }
                    }
                }
            }

            ViewBag.ChartData = dateTimesList;
            return(View(model));
        }
Exemplo n.º 29
0
        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));
        }
Exemplo n.º 30
0
        public async Task <IActionResult> Index(int?id, int childId = 0)
        {
            _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;
            }

            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))
            {
                _userIsProgenyAdmin = true;
                userAccessLevel     = (int)AccessLevel.Private;
            }

            ApplicationUser currentUser = new ApplicationUser();

            currentUser.TimeZone = userinfo.Timezone;
            var eventsList = await _progenyHttpClient.GetCalendarList(_progId, userAccessLevel); // _context.CalendarDb.AsNoTracking().Where(e => e.ProgenyId == _progId).ToList();

            eventsList = eventsList.OrderBy(e => e.StartTime).ToList();
            CalendarItemViewModel events = new CalendarItemViewModel();

            events.IsAdmin    = _userIsProgenyAdmin;
            events.UserData   = currentUser;
            events.Progeny    = progeny;
            events.EventsList = new List <CalendarItem>();

            foreach (CalendarItem ev in eventsList)
            {
                if (ev.AccessLevel == (int)AccessLevel.Public || ev.AccessLevel >= userAccessLevel)
                {
                    if (ev.StartTime.HasValue && ev.EndTime.HasValue)
                    {
                        ev.StartTime = TimeZoneInfo.ConvertTimeFromUtc(ev.StartTime.Value,
                                                                       TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone));
                        if (ev.AllDay)
                        {
                            ev.EndTime = TimeZoneInfo.ConvertTimeFromUtc(ev.EndTime.Value + TimeSpan.FromDays(1),
                                                                         TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone));
                        }
                        else
                        {
                            ev.EndTime = TimeZoneInfo.ConvertTimeFromUtc(ev.EndTime.Value,
                                                                         TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone));
                        }
                        // ToDo: Replace format string with configuration or userdefined value
                        ev.StartString = ev.StartTime.Value.ToString("yyyy-MM-dd") + "T" + ev.StartTime.Value.ToString("HH:mm:ss");
                        ev.EndString   = ev.EndTime.Value.ToString("yyyy-MM-dd") + "T" + ev.EndTime.Value.ToString("HH:mm:ss");
                        events.EventsList.Add(ev);
                    }
                }
            }


            return(View(events));
        }