Example #1
0
 public ActionResult Main()
 {
     Session["status"] = "Medicine Information";
     if (Session["LoginUserName"] == null)
     {
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         var viewModel = new InfoAndCategoryViewModel();
         viewModel.Usage = GetUsageListItemAsync();
         Search();
         return(View(viewModel));
     }
 }
Example #2
0
        public ActionResult Search()
        {
            var Model = new List <InfoAndCategoryViewModel>();
            List <InfoAndCategoryViewModel> Infolist = new List <InfoAndCategoryViewModel>();
            string Id       = null;
            string Category = null;
            string Usage    = null;
            InfoMedicineContext     dbMedicine = new InfoMedicineContext();
            MedicineCategoryContext dbCategory = new MedicineCategoryContext();

            if (Request.Form.Count > 0)
            {
                if ((Request.Form.Get("ID")) != "default")
                {
                    Id = Request.Form.Get("ID").ToString();
                }
                if ((Request.Form.Get("category")) != "default")
                {
                    Category = Request.Form.Get("category").ToString();
                }
                if ((Request.Form.Get("usage")) != "default")
                {
                    Usage = Request.Form.Get("usage").ToString();
                }
            }
            else
            {
                if (Session["ID"] != null)
                {
                    Id = Session["ID"].ToString();
                }
                if (Session["category"] != null)
                {
                    Category = Session["category"].ToString();
                }
                if (Session["usage"] != null)
                {
                    Usage = Session["usage"].ToString();
                }
            }
            if (Id == "")
            {
                Id = null;
            }
            if (Category == "--select--")
            {
                Category = null;
            }

            if (Id == null && Category == null && Usage == null)
            {
                Infolist = _infoAndCategoryProvider.GetInfoAndCategory();
                for (int i = 0; i < Infolist.Count; i++)
                {
                    InfoAndCategoryViewModel List = new InfoAndCategoryViewModel();
                    List.ID       = Infolist[i].ID;
                    List.name     = Infolist[i].name;
                    List.origin   = Infolist[i].origin;
                    List.PD       = Infolist[i].PD;
                    List.EXP      = Infolist[i].EXP;
                    List.price    = Infolist[i].price;
                    List.category = Infolist[i].category;
                    List.usage    = Infolist[i].usage;
                    Model.Add(List);
                }
                ViewBag.length = Infolist.Count;
                System.Web.HttpContext.Current.Session["Category"] = null;
                System.Web.HttpContext.Current.Session["Usage"]    = null;
            }
            else if (Id == null && Category == null && Usage != null)
            {
                Infolist = _infoAndCategoryProvider.GetInfoAndCategoryByUsage(Usage);
                for (int i = 0; i < Infolist.Count; i++)
                {
                    InfoAndCategoryViewModel List = new InfoAndCategoryViewModel();
                    List.ID       = Infolist[i].ID;
                    List.name     = Infolist[i].name;
                    List.origin   = Infolist[i].origin;
                    List.PD       = Infolist[i].PD;
                    List.EXP      = Infolist[i].EXP;
                    List.price    = Infolist[i].price;
                    List.category = Infolist[i].category;
                    List.usage    = Infolist[i].usage;
                    Model.Add(List);
                }
                ViewBag.length = Infolist.Count;
                System.Web.HttpContext.Current.Session["Category"] = null;
                System.Web.HttpContext.Current.Session["Usage"]    = Usage;
            }
            else if (Id == null && Category != null && Usage == null)
            {
                Infolist = _infoAndCategoryProvider.GetInfoAndCategoryByCategory(Category);
                for (int i = 0; i < Infolist.Count; i++)
                {
                    InfoAndCategoryViewModel List = new InfoAndCategoryViewModel();
                    List.ID       = Infolist[i].ID;
                    List.name     = Infolist[i].name;
                    List.origin   = Infolist[i].origin;
                    List.PD       = Infolist[i].PD;
                    List.EXP      = Infolist[i].EXP;
                    List.price    = Infolist[i].price;
                    List.category = Infolist[i].category;
                    List.usage    = Infolist[i].usage;
                    Model.Add(List);
                }
                System.Web.HttpContext.Current.Session["Category"] = Category;
                System.Web.HttpContext.Current.Session["Usage"]    = null;
            }
            else if (Id == null && Category != null && Usage != null)
            {
                Infolist = _infoAndCategoryProvider.GetInfoAndCategoryByCategoryAndUsage(Category, Usage);
                for (int i = 0; i < Infolist.Count; i++)
                {
                    InfoAndCategoryViewModel List = new InfoAndCategoryViewModel();
                    List.ID       = Infolist[i].ID;
                    List.name     = Infolist[i].name;
                    List.origin   = Infolist[i].origin;
                    List.PD       = Infolist[i].PD;
                    List.EXP      = Infolist[i].EXP;
                    List.price    = Infolist[i].price;
                    List.category = Infolist[i].category;
                    List.usage    = Infolist[i].usage;
                    Model.Add(List);
                }
                System.Web.HttpContext.Current.Session["Category"] = Category;
                System.Web.HttpContext.Current.Session["Usage"]    = Usage;
            }
            else if (Id != null)
            {
                Infolist = _infoAndCategoryProvider.GetInfoAndCategorybyId(Id);
                for (int i = 0; i < Infolist.Count; i++)
                {
                    InfoAndCategoryViewModel List = new InfoAndCategoryViewModel();
                    List.ID       = Infolist[i].ID;
                    List.name     = Infolist[i].name;
                    List.origin   = Infolist[i].origin;
                    List.PD       = Infolist[i].PD;
                    List.EXP      = Infolist[i].EXP;
                    List.price    = Infolist[i].price;
                    List.category = Infolist[i].category;
                    List.usage    = Infolist[i].usage;
                    Model.Add(List);
                }
            }


            InfoMedicineList = Model;
            int pageindex   = 1;
            var recordCount = InfoMedicineList.Count();

            if (Request.QueryString["page"] != null)
            {
                pageindex = Convert.ToInt32(Request.QueryString["page"]);
            }
            const int PAGE_SZ = 10;

            ViewBag.Medicine = InfoMedicineList.OrderBy(c => c.ID).Skip((pageindex - 1) * PAGE_SZ).Take(PAGE_SZ).ToList();
            ViewBag.Pager    = new PagerHelper()
            {
                PageIndex   = pageindex,
                PageSize    = PAGE_SZ,
                RecordCount = recordCount
            };
            return(View(Model));
        }