Beispiel #1
0
        public IActionResult SearchStore(int id)
        {
            int total    = DrupStoreRes.GetAll().Count(i => i.status == 1);
            var pageSize = 5;
            int page;

            if (id == null)
            {
                page = 1;
            }
            else
            {
                page = id;
            }

            var skip             = pageSize * (page - 1);
            var canPage          = skip < total;
            List <DrugStore> lst = DrupStoreRes.GetAll().Where(a => a.status == 1).Skip(skip).Take(pageSize).ToList();

            int pagetotal = FunctionUtility.CalcTotalPage(total, 5);

            ViewBag.page = pagetotal;
            List <DrugStore>    lst1     = DrupStoreRes.GetTopfive().ToList();
            List <District>     dis      = DistrictRes.GetAll();
            List <DrugCategory> Category = DrugCategoryRes.GetAll();

            ViewData["Category"] = Category;
            ViewData["Distrist"] = dis;
            ViewData["Topfive"]  = lst1;
            return(View(lst));
        }
Beispiel #2
0
        public IActionResult Index()
        {
            List <DrugStore> lst = DrupStoreRes.GetAll();

            if (((ClaimsIdentity)User.Identity).FindFirst("GroupId").Value == "1")
            {
                lst = DrupStoreRes.GetAll();
            }
            else
            {
                lst = DrupStoreRes.GetAll().Where(i => i.iduser.ToString() == ((ClaimsIdentity)User.Identity).FindFirst("UserId").Value&& i.status == 1).ToList();
            }
            var listloainhathuoc = DrugCategoryRes.GetAll();

            var map = new Dictionary <int, string>();

            foreach (var list in listloainhathuoc)
            {
                map.Add(list.categoryId, list.categoryName);
            }
            ViewBag.list = map;

            var listdistrict = DistrictRes.GetAll();

            ViewBag.listdistric = listdistrict;
            return(View(lst));
        }
        public async Task <IActionResult> UpdateStore(DrugStore model, IFormFile file)
        {
            var listloainhathuoc = DrugCategoryRes.GetAll();

            ViewBag.listloai = listloainhathuoc.Select(x => new SelectListItem
            {
                Text  = x.categoryName,
                Value = x.categoryId.ToString()
            }).ToList();
            var listdistrict = DistrictRes.GetAll();

            ViewBag.listdistrict = listdistrict.Select(x => new SelectListItem
            {
                Text  = x.Name,
                Value = x.ID.ToString()
            }).ToList();

            if (ModelState.IsValid)
            {
                if (file != null && file.Length > 0)
                {
                    var    fileName = Path.GetFileName(file.FileName);
                    string type     = fileName.Substring(fileName.IndexOf("."));
                    if (type.Equals(".jpg") || type.Equals(".png") || type.Equals(".gif") ||
                        type.Equals(".jpeg"))
                    {
                        var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\upload", fileName);
                        using (var fileSteam = new FileStream(filePath, FileMode.Create))
                        {
                            await file.CopyToAsync(fileSteam);
                        }
                        model.imgSrc = fileName;
                    }
                    else if (model.imgSrc == null)
                    {
                        TempData["AlertMessageError"] = "Vui lòng Chọn Đúng file ảnh ";
                        return(RedirectToAction("UpdateStore", new { @id = model.ID }));
                    }
                }
                DateTime dt         = DateTime.Parse(model.openTime);
                string   openTime   = dt.ToString("HH:mm:ss");
                DateTime dt1        = DateTime.Parse(model.closedTime);
                string   closedTime = dt1.ToString("HH:mm:ss");
                object[] value      = new object[] { model.ID, "" + model.name, "" + model.address, "" + model.phone, "" + model.district, "" + model.imgSrc, model.status,
                                                     model.categoryId, "" + model.description, "" + openTime, "" + closedTime, "" + model.lat, "" + model.lng };
                String   errMessage = "";
                int      errorCode  = 0;
                String[] ouput      = null;
                bool     result     = DrupStoreRes.SaveStore(value, ref ouput, ref errorCode, ref errMessage);
                if (result)
                {
                    TempData["AlertMessage"] = "Cập nhật Nhà Thuốc Thành Công";
                    return(RedirectToAction("ListStore"));
                }
            }
            return(View(model));
        }
        public IActionResult InsertStore()
        {
            var listloainhathuoc = DrugCategoryRes.GetAll();

            ViewBag.listloai = listloainhathuoc.Select(x => new SelectListItem
            {
                Text  = x.categoryName,
                Value = x.categoryId.ToString()
            }).ToList();

            var listdistrict = DistrictRes.GetAll();

            ViewBag.listdistrict = listdistrict.Select(x => new SelectListItem
            {
                Text  = x.Name,
                Value = x.ID.ToString()
            }).ToList();
            return(View());
        }
        public ActionResult UpdateStore(int id)
        {
            DrugStore lstid            = DrupStoreRes.GetAll().Where(i => i.ID == id).FirstOrDefault();
            var       listloainhathuoc = DrugCategoryRes.GetAll();

            ViewBag.listloai = listloainhathuoc.Select(x => new SelectListItem
            {
                Text  = x.categoryName,
                Value = x.categoryId.ToString()
            }).ToList();
            var listdistrict = DistrictRes.GetAll();

            ViewBag.listdistrict = listdistrict.Select(x => new SelectListItem
            {
                Text  = x.Name,
                Value = x.ID.ToString()
            }).ToList();
            return(View(lstid));
        }
        public IActionResult ListDistrict()
        {
            List <District> lst = DistrictRes.GetAll();

            return(View(lst));
        }