Esempio n. 1
0
        public async Task <IActionResult> About()
        {
            int comp_id = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value);
            var company = await _context.Companies.FirstOrDefaultAsync(c => c.ID == comp_id);

            var departments = await _context.Departments.Where(d => d.CompanyID == comp_id).ToListAsync();

            foreach (Department dep in departments)
            {
                var workers = await _context.Workers.Where(x => x.DepartmentID == dep.ID).ToListAsync();

                List <UserPlusWorkerModel> userPlusWorkers = new List <UserPlusWorkerModel>();
                if (workers != null)
                {
                    foreach (Worker w in workers)
                    {
                        UserPlusWorkerModel userPlusWorkerModel = new UserPlusWorkerModel(w.FirstName, w.SecondName, w.InviteCode);
                        User user = await _context.Users.Where(u => u.WorkerID == w.ID).FirstOrDefaultAsync();

                        if (user != null)
                        {
                            userPlusWorkerModel.RegistrationDate = user.RegistrationDate;
                            userPlusWorkerModel.Email            = user.Email;
                        }
                        userPlusWorkers.Add(userPlusWorkerModel);
                    }
                    dep.UserPlusWorkers = userPlusWorkers;
                }
            }
            company.Departments = departments;
            return(View(company));
        }
Esempio n. 2
0
        public async Task <IActionResult> Files()
        {
            int comp_id = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value);
            var files   = await _context.Files.Where(f => f.CompanyID == comp_id).ToListAsync();

            foreach (Models.File f in  files)
            {
                User user = await _context.Users.Where(w => w.ID == f.UserID).FirstOrDefaultAsync();

                Worker worker = await _context.Workers.Where(w => w.ID == user.WorkerID).FirstOrDefaultAsync();

                UserPlusWorkerModel model = new UserPlusWorkerModel(worker.FirstName, worker.SecondName,
                                                                    user.Email);
                f.UserPlusWorker = model;
            }
            return(View(files));
        }
Esempio n. 3
0
        public async Task <IActionResult> TopicChat(int?id)
        {
            if (id != null)
            {
                Topic topic = await _context.Topics.Where(t => t.ID == id).FirstOrDefaultAsync();

                if (topic != null)
                {
                    int  comp_id = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value);
                    int  user_id = Int32.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
                    User user    = await _context.Users.Where(u => u.ID == user_id).FirstOrDefaultAsync();

                    Worker worker = await _context.Workers.Where(w => w.ID == user.WorkerID).FirstOrDefaultAsync();

                    TopicMessagePlusUser topicMessagePlusUser = new TopicMessagePlusUser
                    {
                        CompanyID  = comp_id,
                        UserID     = user_id,
                        TopicID    = topic.ID,
                        FirstName  = worker.FirstName,
                        SecondName = worker.SecondName,
                        TopicTitle = topic.Title
                    };
                    var TopicMessages = await _context.TopicMessages.Where(t => t.TopicID == topic.ID).ToListAsync();

                    foreach (var topicmes in TopicMessages)
                    {
                        User _user = await _context.Users.Where(u => u.ID == topicmes.UserID).FirstOrDefaultAsync();

                        Worker _worker = await _context.Workers.Where(w => w.ID == _user.WorkerID).FirstOrDefaultAsync();

                        UserPlusWorkerModel userPlusWorkerModel =
                            new UserPlusWorkerModel(_worker.FirstName, _worker.SecondName, _user.Email);
                        topicmes.UserPlusWorker = userPlusWorkerModel;
                    }
                    topicMessagePlusUser.TopicMessages = TopicMessages;
                    return(View(topicMessagePlusUser));
                }
            }
            return(NotFound());
        }
Esempio n. 4
0
        public async Task <IActionResult> Notes()
        {
            int comp_id        = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value);
            var noteCategories = await _context.NoteCategories.Where(nc => nc.CompanyID == comp_id).ToListAsync();

            foreach (NoteCategory noteCategory in noteCategories)
            {
                var notes = await _context.Notes.Where(n => n.NoteCategoryID == noteCategory.ID).ToListAsync();

                foreach (Note note in notes)
                {
                    User user = await _context.Users.Where(w => w.ID == note.UserID).FirstOrDefaultAsync();

                    Worker worker = await _context.Workers.Where(w => w.ID == user.WorkerID).FirstOrDefaultAsync();

                    UserPlusWorkerModel model = new UserPlusWorkerModel(worker.FirstName, worker.SecondName,
                                                                        user.Email);
                    note.UserPlusWorker = model;
                }
                noteCategory.Notes = notes;
            }
            return(View(noteCategories));
        }
Esempio n. 5
0
        public async Task <IActionResult> GroupChat()
        {
            int comp_id  = Int32.Parse(HttpContext.User.FindFirst("CompanyID").Value);
            int user_id  = Int32.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var messages = await _context.GroupChatMessages.Where(m => m.CompanyID == comp_id).ToListAsync();

            User user = await _context.Users.Where(u => u.ID == user_id).FirstOrDefaultAsync();

            Worker worker = await _context.Workers.Where(w => w.ID == user.WorkerID).FirstOrDefaultAsync();

            Department department = await _context.Departments.Where(d => d.ID == worker.DepartmentID).FirstOrDefaultAsync();

            foreach (GroupChatMessage message in messages)
            {
                User _user = await _context.Users.Where(u => u.ID == message.UserID).FirstOrDefaultAsync();

                Worker _worker = await _context.Workers.Where(w => w.ID == _user.WorkerID).FirstOrDefaultAsync();

                UserPlusWorkerModel _model = new UserPlusWorkerModel(_worker.FirstName, _worker.SecondName,
                                                                     _user.Email);
                message.UserPlusWorker = _model;
            }

            GroupMessagePlusUser model = new GroupMessagePlusUser
            {
                UserID         = user_id,
                CompanyID      = comp_id,
                Email          = user.Email,
                FirstName      = worker.FirstName,
                SecondName     = worker.SecondName,
                DepartmentName = department.Title,
                GroupMessages  = messages
            };

            return(View(model));
        }