Ejemplo n.º 1
0
        public async Task <Notification> CreateForUser(string username, Notification notification)
        {
            var dbUser = await dbcontext.Users.FirstOrDefaultAsync(u => u.UserName == username);

            if (dbUser == null)
            {
                return(null);
            }

            var dbQuestion = await dbcontext.Questions.FirstOrDefaultAsync(q => q.Id == notification.QuestionId);

            if (dbQuestion == null)
            {
                return(null);
            }
            DbNotification dbNotification = new DbNotification
            {
                User       = dbUser,
                UserId     = dbUser.Id,
                Question   = dbQuestion,
                QuestionId = dbQuestion.Id,
                Content    = notification.Content,
                Title      = notification.Title,
            };
            var ret = await dbcontext.Notifications.AddAsync(dbNotification);

            await dbcontext.SaveChangesAsync();

            return(DbMapper.MapDbNotification(ret.Entity));
        }
Ejemplo n.º 2
0
 public async Task <ICollection <Notification> > GetByUsername(string username)
 {
     return(await dbcontext.Notifications
            .Include(n => n.User)
            .Where(n => n.User.UserName == username)
            .OrderBy(n => n.Seen)
            .Select(n => DbMapper.MapDbNotification(n))
            .ToListAsync());
 }
Ejemplo n.º 3
0
        public async Task <Notification> Update(Notification notification)
        {
            var dbNotification = await dbcontext.Notifications.FirstOrDefaultAsync(n => n.Id == notification.Id);

            dbNotification.Content    = notification.Content;
            dbNotification.Title      = notification.Title;
            dbNotification.Seen       = notification.Seen;
            dbNotification.Important  = notification.Important;
            dbNotification.QuestionId = notification.QuestionId;
            await dbcontext.SaveChangesAsync();

            return(DbMapper.MapDbNotification(dbNotification));
        }
Ejemplo n.º 4
0
        public async Task <Notification> CreateWithUserId(string userId, Notification notification)
        {
            DbNotification dbNotification = new DbNotification
            {
                UserId     = userId,
                QuestionId = notification.QuestionId,
                Content    = notification.Content,
                Title      = notification.Title,
            };
            var ret = await dbcontext.Notifications.AddAsync(dbNotification);

            await dbcontext.SaveChangesAsync();

            return(DbMapper.MapDbNotification(ret.Entity));
        }
Ejemplo n.º 5
0
 public async Task <Notification> GetById(int nId)
 {
     return(DbMapper.MapDbNotification(await dbcontext.Notifications.Include(n => n.User).FirstOrDefaultAsync(n => n.Id == nId)));
 }