Beispiel #1
0
        public async Task <IActionResult> DeleteManageAccounts(List <string> model)
        {
            var dict     = new Dictionary <String, object>();
            var response = new List <String>();
            var errors   = new List <Error>();

            foreach (string id in model)
            {
                var user = await _userManager.FindByIdAsync(id);

                if (user == null)
                {
                    errors.Add(new Error
                    {
                        Type    = 1,
                        Message = "This id " + id + " don't exist",
                    });
                    continue;
                }
                if (!(await _userManager.IsInRoleAsync(user, "quality assurance") || await _userManager.IsInRoleAsync(user, "academic management")))
                {
                    errors.Add(new Error
                    {
                        Type    = 2,
                        Message = "The user " + user.UserName + " is not a quality assurance or academic management",
                    });
                    continue;
                }

                var listLog = await(from logs in _userContext.UserLog
                                    where logs.UserId.Contains(id)
                                    select logs).ToListAsync();

                await _logDAO.DeleteLogs(listLog);

                var listPrivateMessages = await(from messages in _userContext.PrivateMessages
                                                where messages.SenderId.Contains(id) || messages.ReceiverId.Contains(id)
                                                select messages).ToListAsync();

                await _privateMessageDAO.DeletePrivateMessages(listPrivateMessages);

                var listAttendances = await(from attendances in _userContext.AttendanceReports
                                            where attendances.UserId.Contains(id)
                                            select attendances).ToListAsync();

                await _attendanceDAO.DeleteAttendance(listAttendances);

                await _userManager.DeleteAsync(user);

                response.Add(id);
            }



            dict.Add("success", response);
            dict.Add("failed", errors);

            return(new OkObjectResult(dict));
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteTeacher(List <string> teacherIdList)
        {
            var dict     = new Dictionary <String, object>();
            var response = new List <String>();
            var errors   = new List <Error>();

            foreach (string id in teacherIdList)
            {
                var user = await _userManager.FindByIdAsync(id);

                var room = await _roomContext.RoomUserLink.FirstOrDefaultAsync(x => x.UserId == id);

                if (user == null)
                {
                    errors.Add(new Error
                    {
                        Type    = 1,
                        Message = "This id " + id + " don't exist",
                    });
                    continue;
                }
                if (!await _userManager.IsInRoleAsync(user, "teacher"))
                {
                    errors.Add(new Error
                    {
                        Type    = 2,
                        Message = "The user " + user.UserName + " is not a teacher",
                    });
                    continue;
                }
                if (room != null)
                {
                    errors.Add(new Error
                    {
                        Type    = 3,
                        Message = "Teacher " + user.UserName + " is still linked to a classroom",
                    });
                    continue;
                }

                var listLog = await(from logs in _userContext.UserLog
                                    where logs.UserId.Contains(id)
                                    select logs).ToListAsync();

                await _logDAO.DeleteLogs(listLog);

                var listPrivateMessages = await(from messages in _userContext.PrivateMessages
                                                where messages.SenderId.Contains(id) || messages.ReceiverId.Contains(id)
                                                select messages).ToListAsync();

                await _privateMessageDAO.DeletePrivateMessages(listPrivateMessages);

                var listAttendances = await(from attendances in _userContext.AttendanceReports
                                            where attendances.UserId.Contains(id)
                                            select attendances).ToListAsync();

                await _attendanceDAO.DeleteAttendance(listAttendances);


                await _userManager.DeleteAsync(user);

                response.Add(id);
            }


            dict.Add("success", response);
            dict.Add("failed", errors);

            return(new OkObjectResult(dict));
        }