private IQueryable <OrderDetail> getSearchModel(FormCollection collection) { IQueryable <OrderDetail> orderdetails = null; var vde = System.Globalization.CultureInfo.InvariantCulture; int Status = collection["lstStatus"] != null?Convert.ToInt32(collection["lstStatus"]) : (!string.IsNullOrEmpty(Request.QueryString["lstStatus"]) ? Convert.ToInt32(Request.QueryString["lstStatus"]) : -1); DateTime dtStart = collection["txtFromDate"] != null?Convert.ToDateTime(collection["txtFromDate"]) : DateTimeWithZone.Now.AddYears(-1); // collection["txtFromDate"] != null ? DateTime.ParseExact(collection["txtFromDate"], "d", System.Globalization.CultureInfo.InvariantCulture) : (!string.IsNullOrEmpty(Request.QueryString["txtFromDate"]) ? DateTime.ParseExact(collection["txtFromDate"], "d", System.Globalization.CultureInfo.InvariantCulture) : DateTimeWithZone.Now.AddYears(-1)); DateTime dtEnd = collection["txtToDate"] != null?Convert.ToDateTime(collection["txtToDate"]) : DateTimeWithZone.Now; // collection["txtToDate"] != null ? DateTime.ParseExact(collection["txtToDate"], "d", System.Globalization.CultureInfo.InvariantCulture) : (!string.IsNullOrEmpty(Request.QueryString["txtToDate"]) ? DateTime.ParseExact(collection["txtToDate"], "d", System.Globalization.CultureInfo.InvariantCulture) : DateTimeWithZone.Now); string DomainName = collection["txtDomainName"] != null?Convert.ToString(collection["txtDomainName"]) : (!string.IsNullOrEmpty(Request.QueryString["txtDomainName"]) ? Convert.ToString(Request.QueryString["txtDomainName"]) : string.Empty); DomainName = string.IsNullOrEmpty(DomainName) ? "" : DomainName; string ExternalOrderID = collection["textOrderNumber"] != null?Convert.ToString(collection["textOrderNumber"]) : (!string.IsNullOrEmpty(Request.QueryString["textOrderNumber"]) ? Convert.ToString(Request.QueryString["textOrderNumber"]) : string.Empty); string product = collection["textProductName"] != null?Convert.ToString(collection["textProductName"]) : (!string.IsNullOrEmpty(Request.QueryString["textProductName"]) ? Convert.ToString(Request.QueryString["textProductName"]) : string.Empty); string InvoiceID = collection["textInvoiceID"] != null?Convert.ToString(collection["textInvoiceID"]) : (!string.IsNullOrEmpty(Request.QueryString["textInvoiceID"]) ? Convert.ToString(Request.QueryString["textInvoiceID"]) : string.Empty); InvoiceID = string.IsNullOrEmpty(InvoiceID) ? "0" : InvoiceID.ToLower().Replace(InvoicePrefix.ToLower(), string.Empty); int invoiceid = (int.TryParse(InvoiceID, out invoiceid) ? invoiceid : 0); ViewBag.Status = Status.ToString(); ViewBag.ToDate = dtEnd.ToShortDateString(); ViewBag.FormDate = dtStart.ToShortDateString(); ViewBag.DomainName = DomainName; ViewBag.ExternalOrderID = ExternalOrderID; ViewBag.product = product; ViewBag.InvoiceID = InvoiceID; //dtStart = Convert.ToDateTime(String.Format(new System.Globalization.CultureInfo("en-US"), "{0:dd/MM/yyyy}", collection["txtFromDate"]));// ?? DateTimeWithZone.Now.AddYears(-1).ToShortDateString())); //dtEnd = Convert.ToDateTime(String.Format(new System.Globalization.CultureInfo("en-US"), "{0:dd/MM/yyyy}", collection["txtToDate"]));//?? DateTimeWithZone.Now.ToShortDateString())); //string fdate = String.Format(new System.Globalization.CultureInfo("en-US"), "{0:dd/MM/yyyy}", dtStart); //string edate = String.Format(new System.Globalization.CultureInfo("en-US"), "{0:dd/MM/yyyy}", dtEnd); //dtStart = DateTimeWithZone.ToDateTime(dtStart.ToShortDateString()); //dtEnd = DateTimeWithZone.ToDateTime(dtEnd.ToShortDateString()); //dtStart = DateTime.ParseExact(fdate, "dd/MM/yyyy", cn.DateTimeFormat); //dtEnd = DateTime.ParseExact(edate, "dd/MM/yyyy", cn.DateTimeFormat); if (Status <= 2) { orderdetails = _repository.Find(x => x.Order.UserID == user.ID && x.Order.SiteID == Site.ID && x.ExternalOrderID != string.Empty && x.OrderStatusID == (Status == -1 ? x.OrderStatusID : Status) && (System.Data.Entity.DbFunctions.DiffDays(dtStart, x.Order.OrderDate) >= 0 && System.Data.Entity.DbFunctions.DiffDays(x.Order.OrderDate, dtEnd) >= 0) && x.ProductName.Contains(string.IsNullOrEmpty(product) ? x.ProductName : product) && (x.CertificateRequest.DomainName.Contains(DomainName)) && x.ExternalOrderID.Equals(string.IsNullOrEmpty(ExternalOrderID) ? x.ExternalOrderID : ExternalOrderID) && x.OrderID.Equals(invoiceid.Equals(0) ? x.OrderID : invoiceid) ).Include(o => o.Order).Include(o => o.Product).Include(o => o.CertificateRequest) .Include(o => o.AuditDetails).Include(o => o.StoreAPIInteraction) .OrderByDescending(o => o.ID); } else if (Status == 3) { orderdetails = _repository.Find(x => x.Order.UserID == user.ID && x.Order.SiteID == Site.ID && x.ExternalOrderID != string.Empty && x.OrderStatusID == (int)OrderStatus.ACTIVE && (DbFunctions.DiffDays(DateTimeWithZone.Now, x.CertificateExpiresOn) <= 0) ).Include(o => o.Order).Include(o => o.Product) .Include(o => o.CertificateRequest).Include(o => o.AuditDetails).Include(o => o.StoreAPIInteraction) .OrderByDescending(o => o.ID); } else { int DateDiff = 0; if (Status == 4) { DateDiff = 30; } else if (Status == 5) { DateDiff = 60; } orderdetails = _repository.Find(x => x.Order.UserID == user.ID && x.Order.SiteID == Site.ID && x.ExternalOrderID != string.Empty && (DbFunctions.DiffDays(DateTimeWithZone.Now, x.CertificateExpiresOn) >= 0 && DbFunctions.DiffDays(DateTimeWithZone.Now, x.CertificateExpiresOn) <= DateDiff) ).Include(o => o.Order) .Include(o => o.Product).Include(o => o.CertificateRequest).Include(o => o.AuditDetails).Include(o => o.StoreAPIInteraction) .OrderByDescending(o => o.ID); } return(orderdetails); }
public ViewResult Search(FormCollection collection, int?page) { ViewBag.StartDate = collection["txtFromDate"] ?? Request.QueryString["txtFromDate"]; ViewBag.EndDate = collection["txtToDate"] ?? Request.QueryString["txtToDate"]; ViewBag.OrderStatus = collection["ddlStatus"] ?? Request.QueryString["ddlStatus"]; ViewBag.AuthCode = collection["txtAuthCode"] ?? Request.QueryString["txtAuthCode"]; ViewBag.ExternalOrderID = collection["txtOrderNumber"] ?? Request.QueryString["txtOrderNumber"]; ViewBag.DomainName = collection["txtDomainName"] ?? Request.QueryString["txtDomainName"]; ViewBag.Product = collection["ddlProduct"] ?? Request.QueryString["ddlProduct"]; ViewBag.InvoiceID = collection["txtInvoiceID"] ?? Request.QueryString["txtInvoiceID"]; BindProducts(); if (ViewBag.StartDate != null) { OrderStatus?eOrderStatus = null; if (!string.IsNullOrEmpty(ViewBag.OrderStatus)) { eOrderStatus = (OrderStatus?)Enum.Parse(typeof(OrderStatus), ViewBag.OrderStatus.ToString(), true); } //var d = DateTime.ParseExact(Convert.ToString(ViewBag.StartDate), "d", System.Globalization.CultureInfo.InvariantCulture); ViewBag.EndDate = !string.IsNullOrEmpty(ViewBag.EndDate) ? Convert.ToString(ViewBag.EndDate).Trim() : ViewBag.EndDate; ViewBag.StartDate = !string.IsNullOrEmpty(ViewBag.StartDate) ? Convert.ToString(ViewBag.StartDate).Trim() : ViewBag.StartDate; DateTime dtStart = ViewBag.StartDate == null ? DateTimeWithZone.Now.Month + "/01/" + DateTimeWithZone.Now.Year : DateTime.ParseExact(ViewBag.StartDate, "d", System.Globalization.CultureInfo.InvariantCulture); DateTime dtEnd = ViewBag.EndDate == null ? DateTimeWithZone.Now : DateTime.ParseExact(ViewBag.EndDate, "d", System.Globalization.CultureInfo.InvariantCulture); string DomainName = ViewBag.DomainName; DomainName = string.IsNullOrEmpty(DomainName) ? "" : DomainName.Trim(); int product = string.IsNullOrEmpty(ViewBag.Product) ? 0 : Convert.ToInt16(ViewBag.Product); string InvoiceID = ViewBag.InvoiceID; InvoiceID = string.IsNullOrEmpty(InvoiceID) ? "-2" : InvoiceID.ToLower().Replace(InvoicePrefix.ToLower(), string.Empty); int invoiceid = WBHelper.ToInt(InvoiceID, -1); string strExternalOrderID = ViewBag.ExternalOrderID, strAuthCode = ViewBag.AuthCode; ViewBag.StartDate = Convert.ToDateTime(dtStart).ToString("MM/dd/yyyy"); ViewBag.EndDate = Convert.ToDateTime(dtEnd).ToString("MM/dd/yyyy"); ViewBag.DomainName = DomainName; ViewBag.OrderStatus = eOrderStatus.ToString(); if (!PagingInputValidator.IsPagingInputValid(ref page)) { return(View()); } var orderInfo = _service.SearchOrder(Site.ID, invoiceid, strExternalOrderID, DomainName, dtStart, dtEnd, product, eOrderStatus, strAuthCode) .OrderByDescending(od => od.OrderDate) .ToPagedList(page.HasValue ? page.Value - 1 : 0, PageSize); orderInfo.ActionName = "Search"; orderInfo.ControllerName = "orders"; if (!PagingInputValidator.IsPagingInputValid(ref page, orderInfo)) { return(View()); } ViewBag.Message = (orderInfo != null && orderInfo.Count > 0 ? string.Empty : "No order found."); return(View(orderInfo)); } return(View()); }