Example #1
0
        public List <DTO.SampleOrderSearchResultDTO> GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            List <DTO.SampleOrderSearchResultDTO> result = new List <DTO.SampleOrderSearchResultDTO>();

            totalRows = 0;

            //try to get data
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    string SampleOrderUD       = null;
                    string Season              = null;
                    string ClientUD            = null;
                    string ClientNM            = null;
                    int?   PurposeID           = null;
                    int?   TransportTypeID     = null;
                    int?   SampleOrderStatusID = null;
                    if (filters.ContainsKey("SampleOrderUD") && !string.IsNullOrEmpty(filters["SampleOrderUD"].ToString()))
                    {
                        SampleOrderUD = filters["SampleOrderUD"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("Season") && filters["Season"] != null && !string.IsNullOrEmpty(filters["Season"].ToString()))
                    {
                        Season = filters["Season"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("ClientUD") && !string.IsNullOrEmpty(filters["ClientUD"].ToString()))
                    {
                        ClientUD = filters["ClientUD"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("ClientNM") && !string.IsNullOrEmpty(filters["ClientNM"].ToString()))
                    {
                        ClientNM = filters["ClientNM"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("PurposeID") && filters["PurposeID"] != null && !string.IsNullOrEmpty(filters["PurposeID"].ToString()))
                    {
                        PurposeID = Convert.ToInt32(filters["PurposeID"].ToString());
                    }
                    if (filters.ContainsKey("TransportTypeID") && filters["TransportTypeID"] != null && !string.IsNullOrEmpty(filters["TransportTypeID"].ToString()))
                    {
                        TransportTypeID = Convert.ToInt32(filters["TransportTypeID"].ToString());
                    }
                    if (filters.ContainsKey("SampleOrderStatusID") && filters["SampleOrderStatusID"] != null && !string.IsNullOrEmpty(filters["SampleOrderStatusID"].ToString()))
                    {
                        SampleOrderStatusID = Convert.ToInt32(filters["SampleOrderStatusID"].ToString());
                    }
                    totalRows = context.Sample3Mng_function_SearchSampleOrder(SampleOrderUD, Season, ClientUD, ClientNM, PurposeID, TransportTypeID, SampleOrderStatusID, orderBy, orderDirection).Count();
                    var data = context.Sample3Mng_function_SearchSampleOrder(SampleOrderUD, Season, ClientUD, ClientNM, PurposeID, TransportTypeID, SampleOrderStatusID, orderBy, orderDirection);
                    result = converter.DB2DTO_SampleOrderSearchResultList(data.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(result);
        }