Exemplo n.º 1
0
        public async Task <IActionResult> OnPostSearch([FromBody] SearchPersonRelativeQuery command)
        {
            try
            {
                List <SearchedPersonRelative> result = new List <SearchedPersonRelative>();
                result = await Mediator.Send(command);

                return(new JsonResult(new UIResult()
                {
                    Data = new { list = result },
                    Status = UIStatus.Success,
                    Text = string.Empty,
                    Description = string.Empty
                }));
            }
            catch (Exception ex)
            {
                return(new JsonResult(new UIResult()
                {
                    Data = null,
                    Status = UIStatus.Failure,
                    Text = CustomMessages.InternalSystemException,

                    Description = ex.Message
                }));
            }
        }
Exemplo n.º 2
0
        public async Task <List <SearchedPersonRelative> > SearchPersonRelative(SearchPersonRelativeQuery request, CancellationToken cancellationToken)
        {
            List <SearchedPersonRelative> result = new List <SearchedPersonRelative>();

            if (request.Id != null)
            {
                using (_context)
                {
                    result = await(from r in _context.Relative

                                   join relationship in _context.Relationship on r.RelationShipId equals relationship.Id into rR
                                   from resultRr in rR.DefaultIfEmpty()
                                   join l in _context.Location on r.LocationId equals l.Id into rL
                                   from resultrL in rL.DefaultIfEmpty()

                                   where r.Id == request.Id
                                   select new SearchedPersonRelative
                    {
                        Id                 = r.Id,
                        FatherName         = r.FatherName,
                        FirstName          = r.FirstName,
                        PersonId           = r.PersonId,
                        LastName           = r.LastName,
                        GrandFatherName    = r.GrandFatherName,
                        RelationShipId     = r.RelationShipId,
                        NidNo              = r.NidNo,
                        Profession         = r.Profession,
                        Address            = r.Address,
                        ContactInfo        = r.ContactInfo,
                        EmailAddress       = r.EmailAddress,
                        Village            = r.Village,
                        LocationId         = r.LocationId,
                        Remark             = r.Remark,
                        RelationShipIdText = resultRr.Name,
                        LocationText       = resultrL.Dari
                    }).ToListAsync(cancellationToken);
                }
            }

            else if (request.PersonId != null)
            {
                using (_context)
                {
                    result = await(from r in _context.Relative
                                   join relationship in _context.Relationship on r.RelationShipId equals relationship.Id into rR
                                   from resultRr in rR.DefaultIfEmpty()
                                   join l in _context.Location on r.LocationId equals l.Id into rL
                                   from resultrL in rL.DefaultIfEmpty()
                                   where r.PersonId == request.PersonId
                                   //where (r.FirstName.Contains(request.FirstName) || string.IsNullOrEmpty(request.FirstName))

                                   //       && (r.FatherName.Contains(request.FatherName) || string.IsNullOrEmpty(request.FatherName))
                                   //       && (r.GrandFatherName.Contains(request.GrandFatherName) || string.IsNullOrEmpty(request.GrandFatherName))
                                   //       && (r.EmailAddress.Contains(request.EmailAddress) || string.IsNullOrEmpty(request.EmailAddress))
                                   //       && ( r.ContactInfo.Contains(request.ContactInfo) || string.IsNullOrEmpty(request.ContactInfo) )
                                   //       && ( r.LocationId == request.LocationId || request.LocationId ==null || request.LocationId == 0.0m)
                                   //       && ( r.RelationShipId == request.RelationShipId || request.RelationShipId == null || request.RelationShipId ==0.0)

                                   select new SearchedPersonRelative
                    {
                        Id                 = r.Id,
                        FatherName         = r.FatherName,
                        FirstName          = r.FirstName,
                        PersonId           = r.PersonId,
                        LastName           = r.LastName,
                        GrandFatherName    = r.GrandFatherName,
                        RelationShipId     = r.RelationShipId,
                        NidNo              = r.NidNo,
                        Profession         = r.Profession,
                        Address            = r.Address,
                        ContactInfo        = r.ContactInfo,
                        EmailAddress       = r.EmailAddress,
                        Village            = r.Village,
                        LocationId         = r.LocationId,
                        Remark             = r.Remark,
                        RelationShipIdText = resultRr.Name,
                        LocationText       = resultrL.Dari
                    }).ToListAsync(cancellationToken);
                }
            }


            return(result);
        }