private ObservableCollection <Manifestacija> DoFilterList() { var pomocna = new ObservableCollection <Manifestacija>(); var pomocna2 = new ObservableCollection <Manifestacija>(); //prvo filtriramo po tipu ako ima neki cekiran if (filterTipovi.Count > 0) { foreach (TipManifestacije tip in filterTipovi) { foreach (Manifestacija m in ListaManifestacija.Manifestacije.Values) { if (m.Tip == null) { continue; } if (m.Tip.Equals(tip)) { pomocna.Add(m); } } } } else { pomocna = new ObservableCollection <Manifestacija>(ListaManifestacija.Manifestacije.Values); } //filtriramo novu listu prema etiketama if (filterEtikete.Count > 0) { foreach (Etiketa et in filterEtikete) { foreach (Manifestacija m in pomocna) { foreach (Etiketa et2 in m.Etikete) { if (et.Equals(et2)) { pomocna2.Add(m); break; } } } } pomocna = new ObservableCollection <Manifestacija>(); } else { pomocna2 = pomocna; pomocna = new ObservableCollection <Manifestacija>(); } //filtriranje po datumu if (!(FromDate.Equals(""))) { Console.WriteLine(FromDate + "aa" + ToDate); DateTime fDate = DateTime.ParseExact(FromDate, "dd-MMM-yy", null); DateTime tDate = DateTime.ParseExact(ToDate, "dd-MMM-yy", null); Console.WriteLine(fDate + "eeeeee" + tDate); foreach (Manifestacija m in pomocna2) { DateTime mDate = DateTime.ParseExact(m.Datum, "M/d/yyyy h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture); if (mDate.Ticks >= fDate.Ticks && mDate.Ticks <= tDate.Ticks) { pomocna.Add(m); } } pomocna2 = new ObservableCollection <Manifestacija>(); } else { pomocna = pomocna2; pomocna2 = new ObservableCollection <Manifestacija>(); } //alkohol filter if (NoAlcohol || BringAlcohol || BuyAlcohol) { foreach (Manifestacija m in pomocna) { if (NoAlcohol && m.StatusSluzenjaAlkohola.Equals("No alcohol")) { pomocna2.Add(m); } if (BringAlcohol && m.StatusSluzenjaAlkohola.Equals("You can bring alcohol")) { pomocna2.Add(m); } if (BuyAlcohol && m.StatusSluzenjaAlkohola.Equals("You can buy alcohol")) { pomocna2.Add(m); } } pomocna = new ObservableCollection <Manifestacija>(); } else { pomocna2 = pomocna; pomocna = new ObservableCollection <Manifestacija>(); } //cene filter if (Free || Low || Medium || High) { foreach (Manifestacija m in pomocna2) { if (Free && m.KategorijaCene.Equals("Free")) { pomocna.Add(m); } if (Low && m.KategorijaCene.Equals("Low prices")) { pomocna.Add(m); } if (Medium && m.KategorijaCene.Equals("Meduim prices")) { pomocna.Add(m); } if (High && m.KategorijaCene.Equals("High prices")) { pomocna.Add(m); } } pomocna2 = new ObservableCollection <Manifestacija>(); } else { pomocna = pomocna2; pomocna2 = new ObservableCollection <Manifestacija>(); } //hendikepirani filter if (YesHandic || NoHandic) { foreach (Manifestacija m in pomocna) { if (YesHandic && m.Hendikepirani) { pomocna2.Add(m); } if (NoHandic && !(m.Hendikepirani)) { pomocna2.Add(m); } } pomocna = new ObservableCollection <Manifestacija>(); } else { pomocna2 = pomocna; pomocna = new ObservableCollection <Manifestacija>(); } //pusenje filter if (YesSmoking || NoSmoking) { foreach (Manifestacija m in pomocna2) { if (YesSmoking && m.Pusenje) { pomocna.Add(m); } if (NoSmoking && !(m.Pusenje)) { pomocna2.Add(m); } } pomocna2 = new ObservableCollection <Manifestacija>(); } else { pomocna = pomocna2; pomocna2 = new ObservableCollection <Manifestacija>(); } //napolju filter if (YesOut || NoOut) { foreach (Manifestacija m in pomocna) { if (YesOut && m.Hendikepirani) { pomocna2.Add(m); } if (NoOut && !(m.Hendikepirani)) { pomocna2.Add(m); } } pomocna = new ObservableCollection <Manifestacija>(); } else { pomocna2 = pomocna; pomocna = new ObservableCollection <Manifestacija>(); } filtrirano = pomocna2; return(filtrirano); }
public ActionResult Index(string LCNo, string FromDate, string ToDate, string currentFilterLC, String currentFilterFrDate, String currentFilterToDate, int?page, int filterBonderId = 0, int BONDERID = 0) { if (TempData["Message"] != null) { ViewBag.Message = TempData["Message"].ToString(); TempData.Remove("Message"); } var requestType = this.HttpContext.Request.RequestType; System.Diagnostics.Debug.WriteLine("requestType = " + requestType); USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission(); var backtobacklcs = db.BACKTOBACKLCs.OrderByDescending(b => b.ID).Include(b => b.BANKBRANCH).Include(b => b.BANK).Include(b => b.BONDER); int pageSize = recordNumbers; int pageNumber = (page ?? 1); if (LCNo != null || FromDate != null || ToDate != null || BONDERID != 0) { page = 1; } else { if (LCNo == null) { LCNo = currentFilterLC; } if (FromDate == null) { FromDate = currentFilterFrDate; } if (ToDate == null) { ToDate = currentFilterToDate; } if (BONDERID == 0) { BONDERID = filterBonderId; } } ViewBag.CurrentFilterLC = LCNo; ViewBag.CurrentFilterFrDate = FromDate; ViewBag.CurrentFilterToDate = ToDate; ViewBag.filterBonderId = BONDERID; ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME"); if ("GET" == requestType) { if (LCNo != null || FromDate != null || ToDate != null || BONDERID != 0) { ViewBag.resultofbonderID = BONDERID; backtobacklcs = GetBackToBackRolesBySearchCriterial(LCNo, FromDate, ToDate, loggedinUser, BONDERID); } if (loggedinUser != null && loggedinUser.BONDERID != null) { ViewBag.resultofbonderID = loggedinUser.BONDERID; backtobacklcs = backtobacklcs.Where(i => i.BONDERID == loggedinUser.BONDERID).OrderByDescending(b => b.ID).Include(b => b.BANKBRANCH).Include(b => b.BANK).Include(b => b.BONDER); } else if (BONDERID == 0 && filterBonderId == 0 && !User.IsInRole("Bonder")) { ViewBag.resultofbonderID = BONDERID; List <BACKTOBACKLC> backtobacklc = new List <BACKTOBACKLC>(); return(View(backtobacklc.ToPagedList(pageNumber, pageSize))); } return(View(backtobacklcs.ToList().ToPagedList(pageNumber, pageSize))); } else if ("POST" == requestType) { if (BONDERID == 0 && filterBonderId == 0 && !User.IsInRole("Bonder")) { ViewBag.resultofbonderID = BONDERID; List <BACKTOBACKLC> backtobacklc = new List <BACKTOBACKLC>(); return(View(backtobacklc.ToPagedList(pageNumber, pageSize))); } if (!string.IsNullOrEmpty(LCNo)) { LCNo = LCNo.Trim(); } System.Diagnostics.Debug.WriteLine("LCNo = " + LCNo + ", FromDate = " + FromDate + ", ToDate = " + ToDate); if (LCNo.Equals(String.Empty) && FromDate.Equals(String.Empty) && ToDate.Equals(String.Empty)) { System.Diagnostics.Debug.WriteLine("if"); } else if ((LCNo != null && !LCNo.Equals(String.Empty)) && (FromDate != null && !FromDate.Equals(String.Empty)) && (ToDate != null && !ToDate.Equals(String.Empty))) { System.Diagnostics.Debug.WriteLine("else if 1"); DateTime fromLCDate = Convert.ToDateTime(FromDate); DateTime toLCDate = Convert.ToDateTime(ToDate); backtobacklcs = backtobacklcs.Where(b => b.LCNUMBER.Contains(LCNo) && (b.LCDATE >= fromLCDate && b.LCDATE <= toLCDate)).Include(b => b.BANKBRANCH).OrderByDescending(b => b.ID); } else if ((FromDate != null && !FromDate.Equals(String.Empty)) && (ToDate != null && !ToDate.Equals(String.Empty))) { System.Diagnostics.Debug.WriteLine("else if 2"); DateTime fromLCDate = Convert.ToDateTime(FromDate); DateTime toLCDate = Convert.ToDateTime(ToDate); backtobacklcs = backtobacklcs.Where(b => (b.LCDATE >= fromLCDate && b.LCDATE <= toLCDate)).Include(b => b.BANKBRANCH).OrderByDescending(b => b.ID); } else if (LCNo != null && !LCNo.Equals(String.Empty)) { System.Diagnostics.Debug.WriteLine("else if 3"); backtobacklcs = backtobacklcs.Where(b => b.LCNUMBER.Contains(LCNo)).Include(b => b.BANKBRANCH).OrderByDescending(b => b.ID); } else if (FromDate != null && !FromDate.Equals(String.Empty)) { System.Diagnostics.Debug.WriteLine("else if 4"); DateTime fromLCDate = Convert.ToDateTime(FromDate); backtobacklcs = backtobacklcs.Where(b => b.LCDATE >= fromLCDate).OrderByDescending(b => b.ID); } else if (ToDate != null && !ToDate.Equals(String.Empty)) { System.Diagnostics.Debug.WriteLine("else if 5"); DateTime toLCDate = Convert.ToDateTime(ToDate); backtobacklcs = backtobacklcs.Where(b => b.LCDATE <= toLCDate).OrderByDescending(b => b.ID); } if (loggedinUser.BONDERID > 0) { ViewBag.resultofbonderID = loggedinUser.BONDERID; backtobacklcs = backtobacklcs.Where(e => e.BONDERID == loggedinUser.BONDERID).OrderByDescending(b => b.ID); } else if (BONDERID > 0) { ViewBag.resultofbonderID = BONDERID; backtobacklcs = backtobacklcs.Where(e => e.BONDERID == BONDERID).OrderByDescending(b => b.ID); } if (loggedinUser != null && loggedinUser.BONDERID != null) { ViewBag.resultofbonderID = loggedinUser.BONDERID; backtobacklcs = backtobacklcs.Where(i => i.BONDERID == loggedinUser.BONDERID).OrderByDescending(b => b.ID).Include(b => b.BANKBRANCH).Include(b => b.BANK).Include(b => b.BONDER); } } else { // Error handel } pageSize = recordNumbers; pageNumber = (page ?? 1); return(View(backtobacklcs.ToPagedList(pageNumber, pageSize))); }