public static void ValidateData(List <StationerySupplier> list) { StationeryRepository srepo = new StationeryRepository(); SupplierRepository repo = new SupplierRepository(); // IEnumerable<StationerySupplier> originalList = _stationeryRepo.GetStationerySupplier(); //check that all supplier id is valid if (list.Select(x => x.SupplierId).Distinct().Except(repo.GetAll().Select(x => x.SupplierId)).Any()) { throw new Exception("Supplier Code is not valid"); } //check that stationery exists as in database, and there is no missing stationery List <string> itemlist = srepo.GetAll().Select(x => x.ItemNum).ToList(); if (list.Select(x => x.ItemNum).Distinct().Except(itemlist).Any() || itemlist.Except(list.Select(x => x.ItemNum).Distinct()).Any()) { throw new Exception("Stationery in the file does not match database"); } //List<string> itemlist2 = list.Where(x => x.Rank == 1).Select(x => x.ItemNum).Distinct().ToList(); if (list.Where(x => x.Rank == 1).Select(x => x.ItemNum).Distinct().Count() != (srepo.GetAll().Select(x => x.ItemNum).Count())) { throw new Exception("Each stationery should have at least one primary supplier"); } //check that composite PK is ok (stationery-rank is distinct) if (list.Select(x => new { x.ItemNum, x.Rank }).Distinct().Count() > list.Count) { throw new Exception("Stationery with duplicated supplier/ranks detected"); } }
// GET: Stationeries public ActionResult Index(string searchString, string currentFilter, int?page, string sortOrder) { ViewBag.CurrentSort = sortOrder; ViewBag.BinSortParm = string.IsNullOrEmpty(sortOrder) ? "bin_desc" : ""; ViewBag.CatSortParm = string.IsNullOrEmpty(sortOrder) ? "cat_desc" : ""; ViewBag.DesSortParm = string.IsNullOrEmpty(sortOrder) ? "des_desc" : ""; ViewBag.QtySortParm = sortOrder == "qty" ? "qty_desc" : "qty"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var result = !string.IsNullOrEmpty(searchString) ? _stationeryRepo.GetByDescription(searchString).ToList() : _stationeryRepo.GetAll().ToList(); switch (sortOrder) { case "bin_desc": result = result.OrderByDescending(s => s.BinNum).ToList(); break; case "cat_desc": result = result.OrderByDescending(s => s.CategoryId).ToList(); break; case "des_desc": result = result.OrderByDescending(s => s.Description).ToList(); break; case "qty_desc": result = result.OrderByDescending(s => s.CurrentQty).ToList(); break; default: result = result.ToList(); break; } var stationeryAll = result.ToPagedList(pageNumber: page ?? 1, pageSize: 15); if (Request.IsAjaxRequest()) { return(PartialView("_Index", stationeryAll)); } return(View(stationeryAll)); }
public IEnumerable <StationeryDTO> GetStationeries() { return(_stationeryRepo.GetAll().Select(item => new StationeryDTO() { ItemNum = item.ItemNum, Category = item.Category.CategoryName, Description = item.Description, ReorderLevel = item.ReorderLevel, ReorderQty = item.ReorderQty, AvailableQty = item.AvailableQty, UnitOfMeasure = item.UnitOfMeasure, BinNum = item.BinNum }) .ToList()); }
public ActionResult Index(string searchString, string currentFilter, int?page, string sortOrder) { ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.CurrentSort = sortOrder; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var stationerys = string.IsNullOrEmpty(searchString) ? _stationeryRepo.GetAll().ToList() : _stationeryRepo.GetByDescription(searchString).ToList(); switch (sortOrder) { case "name_desc": stationerys = stationerys.OrderByDescending(s => s.Description).ToList(); break; default: stationerys = stationerys.ToList(); break; } var stationeryList = stationerys.ToPagedList(pageNumber: page ?? 1, pageSize: 15); if (Request.IsAjaxRequest()) { return(PartialView("_Index", stationeryList)); } return(View(stationeryList)); }