Exemplo n.º 1
0
        public ParentDTO GetParentDetails(int parentId)
        {
            try
            {
                var result  = new StudentDTO();
                var tempRes = _context.Parents.Where(e => e.Id == parentId).Select(student => new ParentDTO
                {
                    Id               = student.Id,
                    Birthday         = student.Birthday,
                    RegistrationDate = student.RegistrationDate,
                    Name             = student.Name,
                    Lastnames        = student.LastName1 + " " + student.LastName2,
                }).FirstOrDefault();

                if (tempRes != null)
                {
                    var kids = _context.Students.Join(_context.StudentParents.Where(e => e.ParentId == parentId),
                                                      student => student.Id,
                                                      studentParent => studentParent.StudentId,
                                                      (student, studentParent) => new StudentDTO
                    {
                        Id   = student.Id,
                        Name = student.Name + " " + student.LastName1 + " " + student.LastName2,
                    }).ToList();

                    if (kids != null)
                    {
                        tempRes.Kids = new List <StudentDTO>();

                        foreach (var par in kids)
                        {
                            tempRes.Kids.Add(par);
                        }
                    }
                }
                return(tempRes);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public StudentDTO GetStudentDetails(int studentId)
        {
            try
            {
                var result = new StudentDTO();
                var tempRes = _context.Students.Where(e => e.Id == studentId).Select(student => new StudentDTO
                {
                    Id = student.Id,
                    Birthday = student.Birthday,
                    RegistrationDate = student.RegistrationDate.ToString(),
                    Name = student.Name,
                    Lastnames = student.LastName1 + " " + student.LastName2,
                    ProfilePic = "",
                    LastName1 = student.LastName1,
                    LastName2 = student.LastName2,
                    Genre = char.Parse(student.Gender)
                }).FirstOrDefault();


                if (tempRes != null)
                {
                    var profilePic = _context.Documents
                        .Where(e => e.StudentId == studentId && e.IsProfilePic == true).OrderByDescending(e=> e.Id).FirstOrDefault();
                    tempRes.ProfilePic = profilePic?.Title;

                    var parents = _context.Parents.Join(_context.StudentParents.Where(e => e.StudentId == studentId && e.DeactivateDatetime == null),
                        parent => parent.Id,
                        studentParent => studentParent.ParentId,
                        (parent, studentParent) => new ParentDTO
                        {
                            Id = parent.Id,
                            Email = parent.Email,
                            Name = parent.Name,
                            Lastnames = parent.LastName1 + " " + parent.LastName2,
                        }).ToList();

                    if (parents != null)
                    {
                        tempRes.Parents = new List<ParentDTO>();

                        foreach (var par in parents)
                        {
                            tempRes.Parents.Add(par);
                        }
                    }

                    var groups = _context.Groups.Join(_context.GroupStudents.Where(e => e.StudentId == studentId && e.DeactivateDatetime == null),
                        group => group.Id,
                        groupStudent => groupStudent.GroupId,
                        (group, groupStudent) => new GroupDTO
                        {
                            Id = group.Id,
                            GroupShortname = group.GroupShortname,
                            LevelName = group.Level.Name,
                            CycleName = group.Cycle.Name,
                            Status = "ACTIVEXXX"
                        }).ToList();

                    if (groups != null)
                    {
                        tempRes.Groups = new List<GroupDTO>();

                        foreach (var g in groups)
                        {
                            tempRes.Groups.Add(g);
                        }
                    }

                }
                return tempRes;

            }
            catch (Exception)
            {

                return null;
            }
        }