示例#1
0
        private async Task <bool> Create(CreateNotifyParams entity)
        {
            try
            {
                var item = new Notification
                {
                    TaskID   = entity.TaskID,
                    UserID   = entity.UserID,
                    Message  = entity.Message,
                    URL      = entity.URL,
                    Function = entity.AlertType.ToString()
                };
                await _context.Notifications.AddAsync(item);

                await _context.SaveChangesAsync();

                if (entity.Users.Count > 0 || entity.Users != null)
                {
                    var details = new List <NotificationDetail>();
                    foreach (var user in entity.Users)
                    {
                        details.Add(new NotificationDetail
                        {
                            NotificationID = item.ID,
                            UserID         = user,
                            Seen           = false
                        });
                    }
                    await _context.AddRangeAsync(details);
                }
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#2
0
        private async Task <bool> AddMessageGroup(int roomid, string message, int userid, List <string> images)
        {
            try
            {
                var project = await _context.Projects.FirstOrDefaultAsync(x => x.Room.Equals(roomid));

                var managers = await _context.Managers.Where(x => x.ProjectID.Equals(project.ID)).Select(x => x.UserID).ToListAsync();

                var members = await _context.TeamMembers.Where(x => x.ProjectID.Equals(project.ID)).Select(x => x.UserID).ToListAsync();

                var listAll          = managers.Union(members);
                var listChats        = new List <Chat>();
                var listParticipants = new List <Participant>();

                //Neu chua co participan thi them vao
                if (!await _context.Participants.AnyAsync(x => x.RoomID == roomid))
                {
                    foreach (var user in listAll)
                    {
                        listParticipants.Add(new Participant
                        {
                            UserID = user,
                            RoomID = roomid
                        });
                    }
                    await _context.AddRangeAsync(listParticipants);
                }
                var chat = new Chat
                {
                    Message   = message,
                    UserID    = userid,
                    ProjectID = project.ID,
                    RoomID    = roomid
                };
                //add message userid
                await _context.AddAsync(chat);

                await _context.SaveChangesAsync();

                if (images.Count > 0)
                {
                    var imagesList = new List <UploadImage>();
                    foreach (var item in images)
                    {
                        imagesList.Add(new UploadImage
                        {
                            ChatID = chat.ID,
                            Image  = item
                        });
                    }
                    await _context.AddRangeAsync(imagesList);

                    await _context.SaveChangesAsync();
                }
                return(true);
            }
            catch
            {
                return(false);

                throw;
            }
            throw new NotImplementedException();
        }