Example #1
0
        public void GetPagedwithFilterbyDateTypeasOrderDate()
        {
            var filter = new RefundRequestListModelFilter
            {
                CustomerName = "John",
                DateType     = (int)FilterDateType.TransactionDate,
                FromDate     = DateTime.Now.AddDays(-30),
                ToDate       = DateTime.Now.AddDays(5)
            };

            int totalRecords;
            var requests = _refundRequestRepository.Get(1, 10, filter, out totalRecords);

            Assert.IsNotNull(requests);
            Assert.IsNotEmpty(requests.ToArray());
        }
Example #2
0
        public ActionResult Index(int pageNumber = 1, RefundRequestListModelFilter filter = null)
        {
            int totalRecords;

            if (filter == null)
            {
                filter = new RefundRequestListModelFilter()
                {
                    RefundRequestStatus = (int)RequestStatus.Pending
                }
            }
            ;
            var model = _refundRequestService.GetPendingRequests(pageNumber, _pageSize, filter, out totalRecords);

            if (model == null)
            {
                model = new RefundRequestListModel();
            }
            model.Filter = filter;

            var currentAction          = ControllerContext.RouteData.Values["action"].ToString();
            Func <int, string> urlFunc =
                pn =>
                Url.Action(currentAction,
                           new
            {
                pageNumber = pn,
                filter.CustomerName,
                filter.DateType,
                filter.FromDate,
                filter.ToDate,
                filter.RefundType,
                filter.RefundRequestStatus,
                filter.CustomerId
            });

            model.PagingModel = new PagingModel(pageNumber, _pageSize, totalRecords, urlFunc);
            return(View(model));
        }
Example #3
0
        public IEnumerable <RefundRequest> Get(int pageNumber, int pageSize, RefundRequestListModelFilter filter, out int totalRecords)
        {
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData       = new LinqMetaData(adapter);
                var refundRequestQuery = from rr in linqMetaData.RefundRequest where rr.IsActive select rr;
                IEnumerable <OrderedPair <long, OrderedPair <long, long> > > orderEventCustomerPair = null;
                IEnumerable <RefundRequest> requests;

                var assignEventCustomer = new Func <RefundRequest, RefundRequest>(rr =>
                {
                    if (orderEventCustomerPair != null)
                    {
                        var pair = orderEventCustomerPair.Where(p => p.FirstValue == rr.OrderId).SingleOrDefault();
                        if (pair != null)
                        {
                            rr.EventId =
                                pair.SecondValue.FirstValue;
                            rr.CustomerId =
                                pair.SecondValue.SecondValue;
                        }
                    }
                    return(rr);
                });
                if (filter == null)
                {
                    var refundRequests = refundRequestQuery.OrderByDescending(rr => rr.RequestedOn).TakePage(pageNumber, pageSize).ToArray();
                    totalRecords = refundRequestQuery.Count();
                    requests     = Mapper.Map <IEnumerable <RefundRequestEntity>, IEnumerable <RefundRequest> >(refundRequests);
                }
                else
                {
                    refundRequestQuery = from rr in linqMetaData.RefundRequest
                                         where
                                         rr.IsActive &&
                                         (filter.RefundRequestStatus < 1
                                                  ? true
                                                  : (rr.RequestStatus == filter.RefundRequestStatus))
                                         select rr;

                    if (filter.CustomerId > 0)
                    {
                        refundRequestQuery = (from od in linqMetaData.OrderDetail
                                              join rr in refundRequestQuery on od.OrderId equals rr.OrderId
                                              where od.ForOrganizationRoleUserId == filter.CustomerId
                                              select rr);
                    }
                    else
                    {
                        if (filter.RefundType > 0)
                        {
                            refundRequestQuery = from rr in refundRequestQuery
                                                 where rr.ReasonType == filter.RefundType
                                                 select rr;
                        }

                        if (!string.IsNullOrEmpty(filter.CustomerName))
                        {
                            refundRequestQuery = (from u in linqMetaData.User
                                                  join oru in linqMetaData.OrganizationRoleUser on u.UserId equals
                                                  oru.UserId
                                                  join od in linqMetaData.OrderDetail on oru.OrganizationRoleUserId equals
                                                  od.ForOrganizationRoleUserId
                                                  join rr in refundRequestQuery on od.OrderId equals rr.OrderId
                                                  where
                                                  (u.FirstName +
                                                   (u.MiddleName.Trim().Length > 0 ? (" " + u.MiddleName + " ") : " ") +
                                                   u.LastName).Contains(filter.CustomerName)
                                                  select rr);
                        }


                        if (filter.FromDate != null || filter.ToDate != null)
                        {
                            var startDate = filter.FromDate ?? DateTime.Now;
                            var endDate   = filter.ToDate ?? DateTime.Now;
                            switch ((FilterDateType)filter.DateType)
                            {
                            case FilterDateType.EventDate:
                                refundRequestQuery = from rr in refundRequestQuery
                                                     join o in linqMetaData.OrderDetail on rr.OrderId equals o.OrderId
                                                     join ecod in linqMetaData.EventCustomerOrderDetail on
                                                     o.OrderDetailId equals ecod.OrderDetailId
                                                     join ec in linqMetaData.EventCustomers on ecod.EventCustomerId
                                                     equals ec.EventCustomerId
                                                     join e in linqMetaData.Events on ec.EventId equals e.EventId
                                                     where (filter.FromDate == null || e.EventDate > startDate)
                                                     &&
                                                     (filter.ToDate == null || e.EventDate <= endDate.AddHours(23).AddMinutes(59))
                                                     select rr;
                                break;

                            case FilterDateType.RequestDate:
                                refundRequestQuery = from rr in refundRequestQuery
                                                     where (filter.FromDate == null || rr.RequestedOn > startDate)
                                                     &&
                                                     (filter.ToDate == null || rr.RequestedOn <= endDate.AddHours(23).AddMinutes(59))
                                                     select rr;
                                break;

                            case FilterDateType.TransactionDate:
                                refundRequestQuery = from rr in refundRequestQuery
                                                     join o in linqMetaData.Order on rr.OrderId equals o.OrderId
                                                     where (filter.FromDate == null || (o.DateCreated > startDate))
                                                     &&
                                                     (filter.ToDate == null || o.DateCreated <= endDate.AddHours(23).AddMinutes(59))
                                                     select rr;
                                break;

                            case FilterDateType.ResolvedDate:
                                refundRequestQuery = from rr in refundRequestQuery
                                                     where (filter.FromDate == null || rr.ProcessedOn > startDate)
                                                     &&
                                                     (filter.ToDate == null || rr.ProcessedOn <= endDate.AddHours(23).AddMinutes(59))
                                                     select rr;
                                break;
                            }
                        }
                    }

                    totalRecords = refundRequestQuery.Count();
                    var refundRequests = refundRequestQuery.OrderByDescending(rr => rr.RequestedOn).TakePage(pageNumber, pageSize).ToArray();
                    requests = Mapper.Map <IEnumerable <RefundRequestEntity>, IEnumerable <RefundRequest> >(refundRequests);
                    requests.ToList().ForEach(rr =>
                    {
                        var refundRequestEntity = refundRequests.Where(entity => entity.RefundRequestId == rr.Id).FirstOrDefault();

                        if (rr.RefundRequestResult == null && refundRequestEntity != null && !string.IsNullOrWhiteSpace(refundRequestEntity.ProcessorNotes))
                        {
                            rr.RefundRequestResult       = new RefundRequestResult();
                            rr.RefundRequestResult.Notes = refundRequestEntity.ProcessorNotes;
                        }
                    });
                }


                orderEventCustomerPair             = GetEventIdCustomerIdPairforOrders(requests.Select(rr => rr.OrderId));
                requests.ToList().ForEach(rr => rr = assignEventCustomer(rr));
                return(requests);
            }
        }