Exemple #1
0
        public IntroducerResponse IntroducerGetList(IntroducerRequest request)
        {
            List <IntroducerDTO> result = null;

            try
            {
                NullSafeCheck(request, "IntroducerRequest");
                UserCheck(request);

                var filter = request.Filter;

                using (var context = new CharityEntities())
                {
                    var query = context.Introducers.AsNoTracking().AsQueryable();
                    if (filter != null)
                    {
                        if (filter.ID > 0)
                        {
                            query = query.Where(p => p.Active && p.ID == filter.ID);
                        }
                        if (filter.PersonID > 0)
                        {
                            query = query.Where(p => p.Active && p.PersonID == filter.PersonID);
                        }
                        else
                        {
                            if (filter.Active != null)
                            {
                                query = query.Where(p => p.Active == filter.Active);
                            }
                            if (filter.CreateDate?.From != null)
                            {
                                query = query.Where(p => p.CreateDate >= filter.CreateDate.From);
                            }
                            if (filter.CreateDate?.To != null)
                            {
                                query = query.Where(p => p.CreateDate <= filter.CreateDate.To);
                            }
                        }
                    }
                    result = query.Select(IntroducerDTOMapper).ToList();

                    if (request.LoadPerson)
                    {
                        var people = context.People.AsNoTracking();
                        result.ForEach(i => i.Person = PersonDTOMapper.Invoke(people.FirstOrDefault(p => p.ID == i.PersonID)));
                    }
                }

                return(new IntroducerResponse {
                    Success = true, ResultList = result
                });
            }
            catch (Exception ex)
            {
                var response = ExceptionToBaseResponse(ex);
                return(response.Cast <IntroducerResponse>());
            }
        }
Exemple #2
0
 public ResponseBase IntroducerSet(IntroducerRequest request)
 {
     try
     {
         NullSafeCheck(request, "IntroducerRequest");
         NullSafeCheck(request.DTO, "IntroducerDTO");
         UserCheck(request, request.DTO);
         var result = EntitySet <IntroducerDTO, Introducer>(request.DTO);
         return(new ResponseBase(true, result));
     }
     catch (Exception ex)
     {
         return(ExceptionToBaseResponse(ex));
     }
 }