protected void UpdateView(string view, object datasource = null)
        {
            if (datasource == null)
            {
                datasource = AssetController.GetAllAssets();
            }
            switch (view)
            {
            case "list":
                AssetViewRepeater.HeaderTemplate = Page.LoadTemplate("/Account/Templates/av_default_header_template.ascx");
                AssetViewRepeater.ItemTemplate   = Page.LoadTemplate("/Account/Templates/av_default_template.ascx");
                AssetViewRepeater.FooterTemplate = Page.LoadTemplate("/Account/Templates/av_default_footer_template.ascx");
                AssetViewRepeater.DataSource     = datasource;
                AssetViewRepeater.DataBind();
                Session["CurrentAvView"] = avSelectedView.Text;
                break;

            case "detail":

                break;

            case "smtile":
                AssetViewRepeater.ItemTemplate = Page.LoadTemplate("/Account/Templates/av_list_template.ascx");
                AssetViewRepeater.DataSource   = datasource;
                AssetViewRepeater.DataBind();
                Session["CurrentAvView"] = avSelectedView.Text;
                break;

            case "mdtile":
                AssetViewRepeater.HeaderTemplate = Page.LoadTemplate("/Account/Templates/av_header_template.ascx");
                AssetViewRepeater.ItemTemplate   = Page.LoadTemplate("/Account/Templates/av_sm_tile_template.ascx");
                AssetViewRepeater.FooterTemplate = Page.LoadTemplate("/Account/Templates/av_footer_template.ascx");
                AssetViewRepeater.DataSource     = datasource;
                AssetViewRepeater.DataBind();
                Session["CurrentAvView"] = avSelectedView.Text;
                break;

            case "lgtile":
                AssetViewRepeater.HeaderTemplate = Page.LoadTemplate("/Account/Templates/av_header_template.ascx");
                AssetViewRepeater.ItemTemplate   = Page.LoadTemplate("/Account/Templates/av_sm_tile_template.ascx");
                AssetViewRepeater.FooterTemplate = Page.LoadTemplate("/Account/Templates/av_footer_template.ascx");
                AssetViewRepeater.DataSource     = datasource;
                AssetViewRepeater.DataBind();
                Session["CurrentAvView"] = avSelectedView.Text;
                break;

            default:
                AssetViewRepeater.HeaderTemplate = Page.LoadTemplate("/Account/Templates/av_default_header_template.ascx");
                AssetViewRepeater.ItemTemplate   = Page.LoadTemplate("/Account/Templates/av_default_template.ascx");
                AssetViewRepeater.FooterTemplate = Page.LoadTemplate("/Account/Templates/av_default_footer_template.ascx");
                AssetViewRepeater.DataSource     = datasource;
                AssetViewRepeater.DataBind();
                Session["CurrentAvView"] = avSelectedView.Text;
                break;
            }
        }
 protected void ViewAll_Click(object sender, EventArgs e)
 {
     UpdateView((Session["CurrentAvView"] as string), AssetController.GetAllAssets());
 }
        protected void FilterCalibrated_Click(object sender, EventArgs e)
        {
            var ret = from a in AssetController.GetAllAssets() where a.IsCalibrated == true select a;

            UpdateView((Session["CurrentAvView"] as string), ret.ToList());
        }
        private List <Asset> AssetSearch(string SearchTerm, string SearchFilter = "asset")
        {
            try
            {
                List <Asset> Results = new List <Asset>();
                if (SearchFilter.ToLower() == "asset")
                {
                    foreach (var asset in AssetController.GetAllAssets())
                    {
                        try
                        {
                            if (asset.AssetNumber != null)
                            {
                                if (asset.AssetNumber.ToUpper().Contains(SearchTerm.ToUpper()))
                                {
                                    if (!Results.Contains(asset))
                                    {
                                        Results.Add((Asset)asset.Clone());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        try
                        {
                            if (asset.AssetName != null)
                            {
                                if (asset.AssetName.ToUpper().Contains(SearchTerm.ToUpper()))
                                {
                                    if (!Results.Contains(asset))
                                    {
                                        Results.Add((Asset)asset.Clone());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        try
                        {
                            if (asset.Description != null)
                            {
                                if (asset.Description.ToUpper().Contains(SearchTerm.ToUpper()))
                                {
                                    if (!Results.Contains(asset))
                                    {
                                        Results.Add((Asset)asset.Clone());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        try
                        {
                            if (asset.ShipTo != null)
                            {
                                if (asset.ShipTo.ToUpper().Contains(SearchTerm.ToUpper()))
                                {
                                    if (!Results.Contains(asset))
                                    {
                                        Results.Add((Asset)asset.Clone());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        try
                        {
                            if (asset.ServiceEngineer != null)
                            {
                                if (asset.ServiceEngineer.ToUpper().Contains(SearchTerm.ToUpper()))
                                {
                                    if (!Results.Contains(asset))
                                    {
                                        Results.Add((Asset)asset.Clone());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        try
                        {
                            if (asset.PersonShipping != null)
                            {
                                if (asset.PersonShipping.ToUpper().Contains(SearchTerm.ToUpper()))
                                {
                                    if (!Results.Contains(asset))
                                    {
                                        Results.Add((Asset)asset.Clone());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        try
                        {
                            if (asset.OrderNumber != "-1")
                            {
                                if (asset.OrderNumber.ToString().ToUpper().Contains(SearchTerm.ToUpper()))
                                {
                                    if (!Results.Contains(asset))
                                    {
                                        Results.Add((Asset)asset.Clone());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    return(Results);
                }
                if (SearchFilter.ToLower() == "history")
                {
                    foreach (var aaa in AssetController.GetAllAssets())
                    {
                        try
                        {
                            foreach (var asset in aaa.History.History)
                            {
                                try
                                {
                                    if (asset.AssetNumber != null)
                                    {
                                        if (asset.AssetNumber.ToUpper().Contains(SearchTerm.ToUpper()))
                                        {
                                            if (!Results.Contains(asset))
                                            {
                                                Results.Add((Asset)asset.Clone());
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (asset.AssetName != null)
                                    {
                                        if (asset.AssetName.ToUpper().Contains(SearchTerm.ToUpper()))
                                        {
                                            if (!Results.Contains(asset))
                                            {
                                                Results.Add((Asset)asset.Clone());
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (asset.Description != null)
                                    {
                                        if (asset.Description.ToUpper().Contains(SearchTerm.ToUpper()))
                                        {
                                            if (!Results.Contains(asset))
                                            {
                                                Results.Add((Asset)asset.Clone());
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (asset.ShipTo != null)
                                    {
                                        if (asset.ShipTo.ToUpper().Contains(SearchTerm.ToUpper()))
                                        {
                                            if (!Results.Contains(asset))
                                            {
                                                Results.Add((Asset)asset.Clone());
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (asset.ServiceEngineer != null)
                                    {
                                        if (asset.ServiceEngineer.ToUpper().Contains(SearchTerm.ToUpper()))
                                        {
                                            if (!Results.Contains(asset))
                                            {
                                                Results.Add((Asset)asset.Clone());
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (asset.PersonShipping != null)
                                    {
                                        if (asset.PersonShipping.ToUpper().Contains(SearchTerm.ToUpper()))
                                        {
                                            if (!Results.Contains(asset))
                                            {
                                                Results.Add((Asset)asset.Clone());
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (asset.OrderNumber != "-1")
                                    {
                                        if (asset.OrderNumber.ToString().ToUpper().Contains(SearchTerm.ToUpper()))
                                        {
                                            if (!Results.Contains(asset))
                                            {
                                                Results.Add((Asset)asset.Clone());
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                        catch { }
                    }
                    foreach (var item in Results)
                    {
                        item.IsHistoryItem = true;
                    }
                    return(Results);
                }

                if (SearchFilter == "Date")
                {
                    return(Results);
                }
            }
            catch { }
            return(new List <Asset>());
        }