示例#1
0
        public async Task <IEnumerable <Notification> > GetNotifications()
        {
            // first search for new deadlines and add notifications
            string userid = _userManager.GetUserId(HttpContext.User);
            User   user   = await _context.User
                            .Include(u => u.Notifications)
                            .ThenInclude(n => n.SubjectList)
                            .Include(u => u.Notifications)
                            .ThenInclude(n => n.SubjectUser)
                            .Include(u => u.SubscribedLists)
                            .ThenInclude(s => s.List)
                            .SingleOrDefaultAsync(u => u.Id == userid);

            user.SubscribedLists.ToList().ForEach(l => {
                // Check if list deadline is soon & if there are already any Deadlinereminders for this list
                if (l.List.IsSoon() && !user.Notifications.Any(n => n.Type == NotificationType.DeadlineReminder && n.SubjectList.ListId == l.ListId))
                {
                    Notification notif = new Notification(user, NotificationType.DeadlineReminder, l.List);
                    _context.Notification.Add(notif);
                }
            });

            await _context.SaveChangesAsync();

            return(user.Notifications.OrderByDescending(n => n.Timestamp));
        }
示例#2
0
        public async Task <IActionResult> CheckItem([FromRoute] int id)
        {
            User user = await _userManager.GetUserAsync(HttpContext.User);

            Item item = await _context.Item.Include(i => i.List).Include(i => i.List.SubscribedUsers).SingleOrDefaultAsync(m => m.ItemId == id);

            if (!item.List.SubscribedUsers.Any(s => s.UserId == user.Id))
            {
                return(Forbid());
            }

            if (item.CheckedByUser == null && item.CheckedByUser == user)
            {
                item.CheckedByUser = null;
            }
            else
            {
                item.CheckedByUser = user;
            }

            await _context.SaveChangesAsync();

            return(Ok());
        }
示例#3
0
        public async Task <IActionResult> SendRequestToUser([FromRoute] string Email)
        {
            User loggedinuser = await _userManager.GetUserAsync(HttpContext.User);

            User selecteduser = await _context.User.Include(u => u.Notifications).FirstOrDefaultAsync(m => m.Email == Email);

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

            new Notification(selecteduser, NotificationType.JoinRequest, null, loggedinuser);

            await _context.SaveChangesAsync();

            return(Ok());
        }
示例#4
0
        private async Task AddListDependencies(List list)
        {
            // TODO: removing items and invites server side

            list.Items.ToList().ForEach(item => {
                if (item.ItemId > 0)
                {
                    // yes the lazy way
                    var trueitem             = _context.Item.First(i => i.ItemId == item.ItemId);
                    trueitem.ProductName     = item.ProductName;
                    trueitem.Description     = item.Description;
                    trueitem.ProductInfoUrl  = item.ProductInfoUrl;
                    trueitem.ProductImageUrl = item.ProductImageUrl;
                    trueitem.Category        = item.Category;
                    trueitem.ItemPriceUsd    = item.ItemPriceUsd;
                }
                else
                {
                    Item newitem = new Item {
                        ProductName     = item.ProductName,
                        Description     = item.Description,
                        ProductInfoUrl  = item.ProductInfoUrl,
                        ProductImageUrl = item.ProductImageUrl,
                        Category        = item.Category,
                        ItemPriceUsd    = item.ItemPriceUsd,
                        List            = list
                    };
                    _context.Item.Add(newitem);
                }
            });

            await _context.SaveChangesAsync();

            list.InvitedUsers.ToList().ForEach(user => {
                // only save existing mailaddresses
                var foundusers = _context.User.Where(u => u.Email == user.User.Email);
                if (foundusers.Count() == 1)
                {
                    try {
                        _context.Database.ExecuteSqlCommand("INSERT INTO [UserListInvite] VALUES (" + list.ListId + ",'" + foundusers.First().Id + "');");
                    } catch { }
                    foundusers.First();
                }
            });

            await _context.SaveChangesAsync();
        }