// GET: Shipments/GenerateHistoryReport public ActionResult GenerateHistoryReport(int?ShippingAccountId, string sortOrder, int?currentShippingAccountId, int?page) { // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var shipmentSearch = new ShipmentsReportViewModel(); shipmentSearch.Shipment = new ShipmentsSearchViewModel(); // Code for paging. ViewBag.CurrentSort = sortOrder; int pageSize = 5; int pageNumber = (page ?? 1); // Retain search conditions for sorting if (ShippingAccountId == null) { ShippingAccountId = currentShippingAccountId; } else { page = 1; } ViewBag.CurrentShippingAccountId = ShippingAccountId; // Populate the ShippingAccountId dropdown list. shipmentSearch.Shipment.ShippingAccounts = PopulateShippingAccountsDropdownList().ToList(); // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var shipmentQuery = from s in db.Shipments // Queryable data type? select new ShipmentsListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.ShippingAccountId }; // Add the condition to select a spefic shipping account if shipping account id is not null. if (ShippingAccountId != null) { // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. //shipmentQuery = shipmentQuery.Where(s => s.ShippingAccountId.Equals(ShippingAccountId)); shipmentQuery = from s in shipmentQuery where s.ShippingAccountId == ShippingAccountId select s; ViewBag.ServiceTypeSortParm = sortOrder == "serviceType" ? "serviceType_desc" : "serviceType"; ViewBag.ShippedDateSortParm = sortOrder == "shippedDate" ? "shippedDate_desc" : "shippedDate"; ViewBag.DeliveredDateSortParm = sortOrder == "deliveredDate" ? "deliveredDate_desc" : "deliveredDate"; ViewBag.RecipientNameSortParm = sortOrder == "recipientName" ? "recipientName_desc" : "recipientName"; ViewBag.OriginSortParm = sortOrder == "origin" ? "origin_desc" : "origin"; ViewBag.DestinationSortParm = sortOrder == "destination" ? "destination_desc" : "destination"; switch (sortOrder) { case "serviceType": shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType); break; case "serviceType_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ServiceType); break; case "shippedDate": shipmentQuery = shipmentQuery.OrderBy(s => s.ShippedDate); break; case "shippedDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ShippedDate); break; case "deliveredDate": shipmentQuery = shipmentQuery.OrderBy(s => s.DeliveredDate); break; case "deliveredDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.DeliveredDate); break; case "recipientName": shipmentQuery = shipmentQuery.OrderBy(s => s.RecipientName); break; case "recipientName_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.RecipientName); break; case "origin": shipmentQuery = shipmentQuery.OrderBy(s => s.Origin); break; case "origin_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Origin); break; case "destination": shipmentQuery = shipmentQuery.OrderBy(s => s.Destination); break; case "destination_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Destination); break; default: shipmentQuery = shipmentQuery.OrderBy(s => s.WaybillId); break; } shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); } else { // Return an empty result if no shipping account id has been selected. shipmentSearch.Shipments = new ShipmentsListViewModel[0].ToPagedList(pageNumber, pageSize); } return(View(shipmentSearch)); }
// GET: Shipments/GenerateHistoryReport public ActionResult GenerateHistoryReport(int?ShippingAccountId, string sortOrder, string ServiceType, DateTime?ShippedDate, DateTime?DeliveredDate, string RecipientName, string Origin, string Destination, string currentServiceType, DateTime?currentShippedDate, DateTime?currentDeliveredDate, string currentRecipientName, string currentOrigin, string currentDestination, int?currentShippingAccountId, int?page, DateTime?FromShippedDate, DateTime?FromDeliveredDate, DateTime?CURRENTToShippedDate, DateTime?CURRENTToDeliveredDate //to be done /*string From_Year, string From_Month, string From_Day, string UNTIL_Year, string UNTIL_Month, string UNTIL_Day*/ ) { // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var shipmentSearch = new ShipmentsReportViewModel(); shipmentSearch.Shipment = new ShipmentsSearchViewModel(); //Code for paging ViewBag.CurrentSort = sortOrder; int pageSize = 5; int pageNumber = (page ?? 1); //DateRangeSearch if (FromShippedDate == null) { FromShippedDate = CURRENTToShippedDate; } else { page = 1; } if (FromDeliveredDate == null) { FromDeliveredDate = CURRENTToDeliveredDate; } else { page = 1; } //Retain search condition for sorting if (ShippingAccountId == null) //ServiceType == null && ShippedDate == null && DeliveredDate == null && RecipientName == null && Origin == null && Destination == null { ShippingAccountId = currentShippingAccountId; ServiceType = currentServiceType; ShippedDate = currentShippedDate; DeliveredDate = currentDeliveredDate; RecipientName = currentRecipientName; Origin = currentOrigin; Destination = currentDestination; } else { page = 1; } ViewBag.CurrentShippingAccountId = ShippingAccountId.GetValueOrDefault(); //ViewBag.CurrentShippingAccountId = ShippingAccountId; does not make visible error in my understanding ViewBag.CurrentServiceType = currentServiceType; ViewBag.CurrentShippedDate = currentShippedDate; ViewBag.CurrentDeliveredDate = currentDeliveredDate; ViewBag.CurrentRecipientName = currentRecipientName; ViewBag.CurrentOrigin = currentOrigin; ViewBag.CurrentDestination = currentDestination; // Populate the ShippingAccountId dropdown list. shipmentSearch.Shipment.ShippingAccounts = PopulateShippingAccountsDropdownList().ToList(); shipmentSearch.Shipment.ShippingAccountId = currentShippingAccountId ?? default(int); // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var shipmentQuery = from s in db.Shipments //orderby s.WaybillId where ShippingAccountId == s.ShippingAccountId select new ShipmentsListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.ShippingAccountId }; //DateRangeSearch // Add the condition to select a spefic ShippedDate user input if ShippedDate is not null. if (FromShippedDate != null) { // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. shipmentQuery = shipmentQuery.Where(a => a.ShippedDate >= FromShippedDate).OrderBy(b => b.WaybillId); } // Add the condition to select a spefic ShippedDate user input if ShippedDate is not null. if (FromDeliveredDate != null) { // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. shipmentQuery = shipmentQuery.Where(a => a.DeliveredDate <= FromDeliveredDate).OrderBy(b => b.WaybillId); } if (User.IsInRole("Employee")) { return(View(db.Shipments.ToList())); } // Add the condition to select a spefic shipping account if shipping account id is not null. if (ShippingAccountId != null) { // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. shipmentQuery = shipmentQuery.Where(a => a.ShippingAccountId == ShippingAccountId).OrderBy(b => b.WaybillId); } /* else * { * // Return an empty result if no shipping account id has been selected. * shipmentSearch.Shipments = new ShipmentsListViewModel[0]; * } */ //Code for osrting on WaybillId, ServiceType, ShippedDate, DeliveredDate, RecipientName, Origin and Destination ViewBag.ServiceTypeSortParm = string.IsNullOrEmpty(sortOrder) ? "ServiceType_desc" : "ServiceType"; ViewBag.ShippedDateSortParm = string.IsNullOrEmpty(sortOrder) ? "ShippedDate_desc" : "ShippedDate"; ViewBag.DeliveredDateSortParm = string.IsNullOrEmpty(sortOrder) ? "DeliveredDate_desc" : "DeliveredDate"; ViewBag.RecipientNameSortParm = string.IsNullOrEmpty(sortOrder) ? "RecipientName_desc" : "RecipientName"; ViewBag.OriginSortParm = string.IsNullOrEmpty(sortOrder) ? "Origin_desc" : "Origin"; ViewBag.DestinationSortParm = string.IsNullOrEmpty(sortOrder) ? "Destination_desc" : "Destination"; switch (sortOrder) { case "ServiceType_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ServiceType); break; case "ShippedDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ShippedDate); break; case "DeliveredDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.DeliveredDate); break; case "RecipientName_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.RecipientName); break; case "Origin_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Origin); break; case "Destination_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Destination); break; case "ServiceType": shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType); break; case "ShippedDate": shipmentQuery = shipmentQuery.OrderBy(s => s.ShippedDate); break; case "DeliveredDate": shipmentQuery = shipmentQuery.OrderBy(s => s.DeliveredDate); break; case "RecipientName": shipmentQuery = shipmentQuery.OrderBy(s => s.RecipientName); break; case "Origin": shipmentQuery = shipmentQuery.OrderBy(s => s.Origin); break; case "Destination": shipmentQuery = shipmentQuery.OrderBy(s => s.Destination); break; default: break; } // shipmentSearch.Shipments = shipmentQuery.ToList(); shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); return(View(shipmentSearch)); }
// GET: Shipments/GenerateHistoryReport public ActionResult GenerateHistoryReport(int?ShippingAccountId, string Shipdaybefore, string Shipmonthbefore, string Shipyearbefore, string Shipdayafter, string Shipmonthafter, string Shipyearafter, string sortOrder, int?currentShippingAccountId, int?page, string currentShipdaybefore, string currentShipmonthbefore, string currentShipyearbefore, string currentShipdayafter, string currentShipmonthafter, string currentShipyearafter ) { // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var shipmentSearch = new ShipmentsReportViewModel(); shipmentSearch.Shipment = new ShipmentsSearchViewModel(); //Code for paging ViewBag.CurrentSort = sortOrder; int pageSize = 5; int pageNumber = (page ?? 1); if (ShippingAccountId == null) { ShippingAccountId = currentShippingAccountId; } else { page = 1; } if (Shipdaybefore == "" || Shipmonthbefore == "" || Shipyearbefore == "") { Shipdaybefore = currentShipdaybefore; Shipmonthbefore = currentShipmonthbefore; Shipyearbefore = currentShipyearbefore; } if (Shipdayafter == "" || Shipmonthafter == "" || Shipyearafter == "") { Shipdayafter = currentShipdayafter; Shipmonthafter = currentShipmonthafter; Shipyearafter = currentShipyearafter; } ViewBag.CurrentShippingAccountId = ShippingAccountId; ViewBag.CurrentShipdaybefore = Shipdaybefore; ViewBag.CurrentShipmonthbefore = Shipmonthbefore; ViewBag.CurrentShipyearbefore = Shipyearbefore; ViewBag.CurrentShipdayafter = Shipdayafter; ViewBag.CurrentShipmonthafter = Shipmonthafter; ViewBag.CurrentShipyearafter = Shipyearafter; // Populate the ShippingAccountId dropdown list. shipmentSearch.Shipment.ShippingAccounts = PopulateShippingAccountsDropdownList().ToList(); shipmentSearch.Shipment.days = PopulateNumberDropdownList(1, 31).ToList(); shipmentSearch.Shipment.months = PopulateNumberDropdownList(1, 12).ToList(); DateTime now = DateTime.Now; shipmentSearch.Shipment.years = PopulateNumberDropdownList(now.Year - 2, now.Year + 5).ToList(); ViewBag.ShippingAccountId = currentShippingAccountId; ViewBag.Shipdaybefore = currentShipdaybefore; ViewBag.Shipmonthbefore = currentShipmonthbefore; ViewBag.Shipyearbefore = currentShipyearbefore; ViewBag.Shipdayafter = currentShipdayafter; ViewBag.Shipmonthafter = currentShipmonthafter; ViewBag.Shipyearafter = currentShipyearafter; // shipmentSearch.Shipment.ShippingAccountId =(int) currentShippingAccountId; // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var shipmentQuery = from s in db.Shipments select new ShipmentsListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.ShippingAccountId }; // Add the condition to select a spefic shipping account if shipping account id is not null. if (ShippingAccountId != null) { DateTime Shipbefore; DateTime Shipafter; DateTime Deliverybefore; DateTime Deliveryafter; int yeart, montht, dayt; // if (ShippedDateF != null) { shipmentQuery = shipmentQuery.Where(s => s.ShippedDate >= ShippedDateF); } if (((Shipdaybefore != "" && Shipmonthbefore != "" && Shipyearbefore != "")) && Shipdaybefore != null && Shipmonthbefore != null && Shipyearbefore != null) { yeart = int.Parse(Shipyearbefore); montht = int.Parse(Shipmonthbefore); dayt = int.Parse(Shipdaybefore); Shipbefore = new DateTime(yeart, montht, dayt); } else { Shipbefore = DateTime.MaxValue; } if (((Shipdayafter != "" && Shipmonthafter != "" && Shipyearafter != "")) && Shipdayafter != null && Shipmonthafter != null && Shipyearafter != null) { yeart = int.Parse(Shipyearafter); montht = int.Parse(Shipmonthafter); dayt = int.Parse(Shipdayafter); Shipafter = new DateTime(yeart, montht, dayt); } else { Shipafter = DateTime.MinValue; } // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. shipmentQuery = shipmentQuery.Where(s => s.ShippingAccountId == ShippingAccountId); shipmentQuery = shipmentQuery.Where(s => s.ShippedDate <= Shipbefore); shipmentQuery = shipmentQuery.Where(s => s.ShippedDate >= Shipafter); ViewBag.ServiceTypeSortParm = sortOrder == "serviceType" ? "serviceType_desc" : "serviceType"; ViewBag.ShippedDateSortParm = sortOrder == "shippedDate" ? "shippedDate_desc" : "shippedDate"; ViewBag.DeliveredDateSortParm = sortOrder == "deliveredDate" ? "deliveredDate_desc" : "deliveredDate"; ViewBag.RecipientNameSortParm = sortOrder == "recipientName" ? "recipientName_desc" : "recipientName"; ViewBag.OriginSortParm = sortOrder == "origin" ? "origin_desc" : "origin"; ViewBag.DestinationSortParm = sortOrder == "destination" ? "destination_desc" : "destination"; switch (sortOrder) { case "serviceType": shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType); break; case "serviceType_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ServiceType); break; case "shippedDate": shipmentQuery = shipmentQuery.OrderBy(s => s.ShippedDate); break; case "shippedDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ShippedDate); break; case "deliveredDate": shipmentQuery = shipmentQuery.OrderBy(s => s.DeliveredDate); break; case "deliveredDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.DeliveredDate); break; case "recipientName": shipmentQuery = shipmentQuery.OrderBy(s => s.RecipientName); break; case "recipientName_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.RecipientName); break; case "origin": shipmentQuery = shipmentQuery.OrderBy(s => s.Origin); break; case "origin_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Origin); break; case "destination": shipmentQuery = shipmentQuery.OrderBy(s => s.Destination); break; case "destination_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Destination); break; default: shipmentQuery = shipmentQuery.OrderBy(s => s.WaybillId); break; } shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); } else { // Return an empty result if no shipping account id has been selected. shipmentSearch.Shipments = new ShipmentsListViewModel[0].ToPagedList(pageNumber, pageSize); } return(View(shipmentSearch)); }
public ActionResult GenerateHistoryReport(int?ShippingAccountId, DateTime?DateFrom, DateTime?DateTo, string sortOrder, int?currentShippingAccountId, int?page) { // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var shipmentSearch = new ShipmentsReportViewModel(); shipmentSearch.Shipment = new ShipmentsSearchViewModel(); // Code for paging. ViewBag.CurrentSort = sortOrder; int pageSize = 5; int pageNumber = (page ?? 1); // Retain search conditions for sorting. if (User.IsInRole("Customer")) { ShippingAccountId = db.ShippingAccounts.Where(s => s.UserName == User.Identity.Name).Select(s => s.ShippingAccountId).Single(); } else if (User.IsInRole("Employee")) { if (ShippingAccountId == null) { ShippingAccountId = currentShippingAccountId; } else { page = 1; } } ViewBag.CurrentShippingAccountId = ShippingAccountId; // Populate the ShippingAccountId dropdown list. shipmentSearch.Shipment.ShippingAccounts = PopulateShippingAccountsDropdownList().ToList(); // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var shipmentQuery = from s in db.Shipments select new ShipmentsListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.SenderId }; // Add the condition to select a spefic shipping account if shipping account id is not null. if (ShippingAccountId != null) { // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. shipmentQuery = shipmentQuery.Where(s => s.ShippingAccountId == ShippingAccountId); // Code for date range search if (DateFrom != null) { shipmentQuery = shipmentQuery.Where(s => s.ShippedDate >= DateFrom).Where(s => s.DeliveredDate >= DateFrom); } if (DateTo != null) { shipmentQuery = shipmentQuery.Where(s => s.ShippedDate <= DateTo).Where(s => s.DeliveredDate <= DateTo); } // Code for sorting. ViewBag.WaybillIdSortParm = string.IsNullOrEmpty(sortOrder) ? "waybillId" : ""; ViewBag.ServiceTypeSortParm = sortOrder == "serviceType" ? "serviceType_desc" : "serviceType"; ViewBag.ShippedDateSortParm = sortOrder == "shippedDate" ? "shippedDate_desc" : "shippedDate"; ViewBag.DeliveredDateSortParm = sortOrder == "deliveredDate" ? "deliveredDate_desc" : "deliveredDate"; ViewBag.RecipientNameSortParm = sortOrder == "recipientName" ? "recipientName_desc" : "recipientName"; ViewBag.OriginSortParm = sortOrder == "origin" ? "origin_desc" : "origin"; ViewBag.DestinationSortParm = sortOrder == "destination" ? "destination_desc" : "destination"; switch (sortOrder) { case "waybillId": shipmentQuery = shipmentQuery.OrderBy(s => s.WaybillId); break; case "serviceType": shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType); break; case "serviceType_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ServiceType); break; case "shippedDate": shipmentQuery = shipmentQuery.OrderBy(s => s.ShippedDate); break; case "shippedDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ShippedDate); break; case "deliveredDate": shipmentQuery = shipmentQuery.OrderBy(s => s.DeliveredDate); break; case "deliveredDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.DeliveredDate); break; case "recipientName": shipmentQuery = shipmentQuery.OrderBy(s => s.RecipientName); break; case "recipientName_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.RecipientName); break; case "origin": shipmentQuery = shipmentQuery.OrderBy(s => s.Origin); break; case "origin_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Origin); break; case "destination": shipmentQuery = shipmentQuery.OrderBy(s => s.Destination); break; case "destination_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Destination); break; default: shipmentQuery = shipmentQuery.OrderBy(s => s.WaybillId); break; } shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); } else { // Return an empty result if no shipping account id has been selected. shipmentSearch.Shipments = new ShipmentsListViewModel[0].ToPagedList(pageNumber, pageSize); } return(View(shipmentSearch)); }
// GET: Shipments/GenerateHistoryReport public ActionResult GenerateHistoryReport(int?CurrentShippingAccountId, DateTime?StartShippedDate, DateTime?EndShippedDate, string sortOrder, int?page) { // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var shipmentSearch = new ShipmentsReportViewModel(); shipmentSearch.Shipment = new ShipmentsSearchViewModel(); // Code for paging ViewBag.CurrentSort = sortOrder; int pageSize = 5; int pageNumber = (page ?? 1); int?shippingAccountId; // Retain search condition for sorting if (User.IsInRole("Customer")) { shippingAccountId = GetUserId(); ViewBag.CurrentShippingAccountId = shippingAccountId; shipmentSearch.Shipment.ShippingAccountId = shippingAccountId.GetValueOrDefault(); shipmentSearch.Shipment.AccountType = db.ShippingAccounts.Find(shippingAccountId).AccountType; ViewBag.DisplayedShippingAccountId = ShowShippingAccountId(shippingAccountId.GetValueOrDefault()); } else { shipmentSearch.Shipment.AccountType = "Employee"; shippingAccountId = null; } if (StartShippedDate == null && EndShippedDate == null) { StartShippedDate = DateTime.MinValue; EndShippedDate = DateTime.MaxValue; } ViewBag.CurrentStartShippedDate = StartShippedDate; ViewBag.CurrentEndShippedDate = EndShippedDate; /* * // Populate the ShippingAccountId dropdown list. * shipmentSearch.Shipment.ShippingAccounts = PopulateShippingAccountsDropdownList().ToList(); * if (CurrentShippingAccountId != null) shipmentSearch.Shipment.ShippingAccountId = (int) CurrentShippingAccountId;*/ // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var shipmentQuery = from s in db.Shipments select new ShipmentsListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.ShippingAccountId, Status = s.Status }; // Code for sorting on properties ViewBag.ServiceTypeSortParm = sortOrder == "ServiceType" ? "ServiceType_desc" : "ServiceType"; ViewBag.ShippedDateSortParm = sortOrder == "ShippedDate" ? "ShippedDate_desc" : "ShippedDate"; ViewBag.DeliveredDateSortParm = sortOrder == "DeliveredDate" ? "DeliveredDate_desc" : "DeliveredDate"; ViewBag.RecipientNameSortParm = sortOrder == "RecipientName" ? "RecipientName_desc" : "RecipientName"; ViewBag.OriginSortParm = sortOrder == "Origin" ? "Origin_desc" : "Origin"; ViewBag.DestinationSortParm = sortOrder == "Destination" ? "Destination_desc" : "Destination"; switch (sortOrder) { case "ServiceType": shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType); break; case "ServiceType_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ServiceType); break; case "ShippedDate": shipmentQuery = shipmentQuery.OrderBy(s => s.ShippedDate); break; case "ShippedDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.ShippedDate); break; case "DeliveredDate": shipmentQuery = shipmentQuery.OrderBy(s => s.DeliveredDate); break; case "DeliveredDate_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.DeliveredDate); break; case "RecipientName": shipmentQuery = shipmentQuery.OrderBy(s => s.RecipientName); break; case "RecipientName_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.RecipientName); break; case "Origin": shipmentQuery = shipmentQuery.OrderBy(s => s.Origin); break; case "Origin_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Origin); break; case "Destination": shipmentQuery = shipmentQuery.OrderBy(s => s.Destination); break; case "Destination_desc": shipmentQuery = shipmentQuery.OrderByDescending(s => s.Destination); break; default: shipmentQuery = shipmentQuery.OrderBy(s => s.WaybillId); break; } //if (User.IsInRole("Customer")) //{ // Add the condition to select a spefic shipping account if shipping account id is not null. if (shippingAccountId != null) { shipmentQuery = shipmentQuery.Where(s => s.ShippingAccountId == shippingAccountId); //shipmentSearch.Shipments = shipmentQuery.ToList(); shipmentQuery = shipmentQuery.Where(s => (s.ShippedDate >= StartShippedDate && s.ShippedDate <= EndShippedDate)); } /*else * { * // Return an empty result if no shipping account id has been selected. * //shipmentSearch.Shipments = new ShipmentsListViewModel[0]; * shipmentQuery = shipmentQuery.Where(s => s.ShippingAccountId == 0); ; * }*/ //} shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); return(View(shipmentSearch)); }
public ActionResult GenerateHistoryReport(int?ShippingAccountId, string sortOrder, int?page, DateTime?ShippedStartDate, DateTime?ShippedEndDate) { // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var shipmentSearch = new ShipmentsReportViewModel(); shipmentSearch.Shipment = new ShipmentsSearchViewModel(); ViewBag.CurrentSort = sortOrder; int pageSize = 5; int pageNumber = (page ?? 1); if (ShippingAccountId == null) { ShippingAccountId = 0; } // Populate the ShippingAccountId dropdown list. shipmentSearch.Shipment.ShippingAccounts = PopulateShippingAccountsDropdownList().ToList(); if (User.IsInRole("Customer")) { shipmentSearch.Shipment.ShippingAccounts = PopulateCustomerShippingAccountsDropdownList().ToList(); //var currShippingAccount = db.Shipments.Where(a => a.ShippingAccount.UserName == User.Identity.Name).Select(a => a.ShippingAccountId).Distinct().ToList(); //if (!currShippingAccount.Contains((int)ShippingAccountId)) //{ // shipmentSearch.Shipments = new ShipmentsListViewModel().ToPagedList; //return View(shipmentSearch); //} } ViewBag.CurrentShippingAccountId = ShippingAccountId; ViewBag.CurrentShippingStartDate = ShippedStartDate; ViewBag.CurrentShippingEndDate = ShippedEndDate; // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var shipmentQuery = from s in db.Shipments select new ShipmentsListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.ShippingAccountId }; if (User.IsInRole("Customer")) { string userName = System.Web.HttpContext.Current.User.Identity.Name; shipmentQuery = from s in db.Shipments where s.ShippingAccount.UserName == userName select new ShipmentsListViewModel { WaybillId = s.WaybillId, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountId = s.ShippingAccountId }; } // Add the condition to select a spefic shipping account if shipping account id is not null. if (ShippingAccountId != null) { // TODO: Construct the LINQ query to retrive only the shipments for the specified shipping account id. shipmentQuery = from s in shipmentQuery where s.ShippingAccountId == ShippingAccountId select s; // shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); } else { // Return an empty result if no shipping account id has been selected. // shipmentSearch.Shipments = new ShipmentsListViewModel[0].ToPagedList(pageNumber, pageSize); shipmentQuery = from s in shipmentQuery where s.ShippingAccountId == 0 select s; // page = 1; } if (ShippedStartDate != null && ShippedEndDate != null) { shipmentQuery = from s in shipmentQuery where s.ShippedDate >= ShippedStartDate && s.ShippedDate <= ShippedEndDate select s; } ViewBag.ServiceTypeSortParm = string.IsNullOrEmpty(sortOrder) ? "serviceType_desc" : ""; ViewBag.ShippedDateSortParm = string.IsNullOrEmpty(sortOrder) ? "shippedDate_desc" : ""; ViewBag.DeliveredDateSortParm = string.IsNullOrEmpty(sortOrder) ? "DeliveredDate_desc" : ""; ViewBag.RecipientNameSortParm = string.IsNullOrEmpty(sortOrder) ? "RecipientName_desc" : ""; ViewBag.OriginSortParm = string.IsNullOrEmpty(sortOrder) ? "Origin_desc" : ""; ViewBag.DestinationSortParm = string.IsNullOrEmpty(sortOrder) ? "Destination_desc" : ""; ViewBag.ShippingAccountIdSortParm = string.IsNullOrEmpty(sortOrder) ? "ShippingAccountId_desc" : ""; switch (sortOrder) { case "serviceType_desc": shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType); break; case "shippedDate_desc": shipmentQuery = shipmentQuery.OrderBy(s => s.ShippedDate); break; case "DeliveredDate_desc": shipmentQuery = shipmentQuery.OrderBy(s => s.DeliveredDate); break; case "RecipientName_desc": shipmentQuery = shipmentQuery.OrderBy(s => s.RecipientName); break; case "Origin_desc": shipmentQuery = shipmentQuery.OrderBy(s => s.ServiceType); break; case "Destination_desc": shipmentQuery = shipmentQuery.OrderBy(s => s.Destination); break; case "ShippingAccountId_desc": shipmentQuery = shipmentQuery.OrderBy(s => s.ShippingAccountId); break; default: shipmentQuery = shipmentQuery.OrderBy(s => s.WaybillId); break; } shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); return(View(shipmentSearch)); }
// GET: Shipments/GenerateHistoryReport public ActionResult GenerateHistoryReport(int?ShippingAccountID, string SortOrder, int?CurrentShippingAccountID, int?page, string StartShippedDate, string EndShippedDate) { if (!Request.IsAuthenticated) { return(View()); } // Instantiate an instance of the ShipmentsReportViewModel and the ShipmentsSearchViewModel. var shipmentSearch = new ShipmentsReportViewModel(); shipmentSearch.Shipment = new ShipmentsSearchViewModel(); //Code for paging. ViewBag.CurrentSort = SortOrder; int pageSize = 5; int pageNumber = (page ?? 1); if (ShippingAccountID == null) { ShippingAccountID = CurrentShippingAccountID; } else { page = 1; } ViewBag.CurrentShippingAccountID = ShippingAccountID; // Populate the ShippingAccountId dropdown list. shipmentSearch.Shipment.ShippingAccounts = PopulateShippingAccountsDropdownList().ToList(); // Initialize the query to retrieve shipments using the ShipmentsListViewModel. var shipmentQuery = from s in db.Shipments select new ShipmentsListViewModel { WaybillID = s.WaybillID, ServiceType = s.ServiceType, ShippedDate = s.ShippedDate, DeliveredDate = s.DeliveredDate, RecipientName = s.RecipientName, NumberOfPackages = s.NumberOfPackages, Origin = s.Origin, Destination = s.Destination, ShippingAccountID = s.ShippingAccountID }; // Add the condition to select a spefic shipping account if shipping account id is not null. if (ShippingAccountID != null && StartShippedDate != null && EndShippedDate != null) { DateTime CStartDate; DateTime CEndDate; shipmentQuery = shipmentQuery.Where(id => id.ShippingAccountID == ShippingAccountID); if (DateTime.TryParse(StartShippedDate, out CStartDate) && DateTime.TryParse(EndShippedDate, out CEndDate)) { shipmentQuery = shipmentQuery.Where(start => start.ShippedDate >= CStartDate && start.ShippedDate <= CEndDate); } else if (StartShippedDate == "" || EndShippedDate == "") { } else { ViewBag.DateError = true; } } else if (StartShippedDate != null && EndShippedDate != null) { DateTime CStartDate; DateTime CEndDate; if (DateTime.TryParse(StartShippedDate, out CStartDate) && DateTime.TryParse(EndShippedDate, out CEndDate)) { shipmentQuery = shipmentQuery.Where(start => start.ShippedDate >= CStartDate && start.ShippedDate <= CEndDate); } else { ViewBag.DateError = true; } } else if (ShippingAccountID != null) { shipmentQuery = shipmentQuery.Where(id => id.ShippingAccountID == ShippingAccountID); } ViewBag.ServiceTypeSortParam = SortOrder == "service_type" ? "service_type_desc" : "service_type"; ViewBag.ShippedDateSortParam = SortOrder == "shipped_date" ? "shipped_date_desc" : "shipped_date"; ViewBag.DeliveredDateSortParam = SortOrder == "delivered_date" ? "delivered_date_desc" : "delivered_date"; ViewBag.RecipientNameSortParam = SortOrder == "recipient_name" ? "recipient_name_desc" : "recipient_name"; ViewBag.OriginSortParam = SortOrder == "origin" ? "origin_desc" : "origin"; ViewBag.DestinationSortParam = SortOrder == "destination" ? "destination_desc" : "destination"; switch (SortOrder) { case "service_type": shipmentQuery = shipmentQuery.OrderBy(st => st.ServiceType); break; case "service_type_desc": shipmentQuery = shipmentQuery.OrderByDescending(st => st.ServiceType); break; case "shipped_date": shipmentQuery = shipmentQuery.OrderBy(st => st.ShippedDate); break; case "shipped_date_desc": shipmentQuery = shipmentQuery.OrderByDescending(st => st.ShippedDate); break; case "delivered_date": shipmentQuery = shipmentQuery.OrderBy(st => st.DeliveredDate); break; case "delivered_date_desc": shipmentQuery = shipmentQuery.OrderByDescending(st => st.DeliveredDate); break; case "recipient_name": shipmentQuery = shipmentQuery.OrderBy(st => st.RecipientName); break; case "recipient_name_desc": shipmentQuery = shipmentQuery.OrderByDescending(st => st.RecipientName); break; case "origin": shipmentQuery = shipmentQuery.OrderBy(st => st.Origin); break; case "origin_desc": shipmentQuery = shipmentQuery.OrderByDescending(st => st.Origin); break; case "destination": shipmentQuery = shipmentQuery.OrderBy(st => st.Destination); break; case "destination_desc": shipmentQuery = shipmentQuery.OrderByDescending(st => st.Destination); break; default: shipmentQuery = shipmentQuery.OrderBy(st => st.WaybillID); break; } if (!User.IsInRole("Employee")) { var q = from s in db.ShippingAccounts where s.UserName == User.Identity.Name select s.ShippingAccountID; int AccountID = q.ToList()[0]; shipmentQuery = shipmentQuery.Where(id => id.ShippingAccountID == AccountID); } shipmentSearch.Shipments = shipmentQuery.ToPagedList(pageNumber, pageSize); return(View(shipmentSearch)); }