public async Task <ActionResult> ProjectsList(ProjectsViewModel model)
        {
            //var orders = (await db.GetProjectRentalOrders(this.ActiveCustomer, TheUser));
            var orders = await GetOrders(this.ActiveCustomer, TheUser);

            orders = model.Process(orders, null, this.ActiveCustomer);

            var dt = new System.Data.DataTable();

            dt.Columns.Add(Resources.RentalOrder, typeof(string));
            dt.Columns.Add(Resources.AccountName, typeof(string));
            dt.Columns.Add(Resources.MachineType, typeof(string));
            dt.Columns.Add(Resources.Brand, typeof(string));
            dt.Columns.Add(Resources.Description, typeof(string));
            dt.Columns.Add(Resources.OnHireDate, typeof(DateTime));
            dt.Columns.Add(Resources.OffHireDate, typeof(string));
            dt.Columns.Add(Resources.ExpectedOffHireDate, typeof(DateTime));
            dt.Columns.Add(Resources.InspectionDate, typeof(string));
            dt.Columns.Add(Resources.SerialNumber, typeof(string));
            dt.Columns.Add(Resources.FleetNumber, typeof(string));
            dt.Columns.Add(Resources.VenueName, typeof(string));
            dt.Columns.Add(Resources.VenueCity, typeof(string));
            dt.Columns.Add(Resources.MachineCategory, typeof(string));
            dt.Columns.Add(Resources.ContactPerson, typeof(string));
            dt.Columns.Add(Resources.OperatorName, typeof(string));

            foreach (var order in orders)
            {
                var row = dt.NewRow();
                row[0]  = order.SalesId;
                row[1]  = order.AccountName;
                row[2]  = order.ProductId;
                row[3]  = order.AssetOverviewItemId;
                row[4]  = order.ItemName;
                row[5]  = order.DateOnHire;
                row[6]  = order.DateOffHire.HasValue ? order.DateOffHire.Value.ToShortDateString() : "";
                row[7]  = order.ExpectedDateOffHire;
                row[8]  = order.InspectionDate;
                row[9]  = order.ObjectId;
                row[10] = order.AssetId;
                row[11] = order.DeliveryName;
                row[12] = order.DeliveryCity;
                row[13] = order.ItemGroupName;
                row[14] = order.ContactPerson;
                row[15] = order.OperatorName;

                dt.Rows.Add(row);
            }

            System.IO.MemoryStream file = ExportToExcel.CreateExcelFile.CreateExcelDocument2(dt);

            return(File(file, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ProjectMachines.xlsx"));
        }
        public async Task <ActionResult> Index()
        {
            var model = new ProjectsViewModel();

            // string key = GetKey(this.ActiveCustomer, TheUser);
            // InMemoryCache cacheProvider = new InMemoryCache();
            // IEnumerable<RentalOrder> orders = await cacheProvider.GetOrSet(key, () =>
            //{
            //    return db.GetProjectRentalOrders(this.ActiveCustomer, TheUser);

            //});

            var orders = await GetOrders(this.ActiveCustomer, TheUser);

            //IEnumerable<RentalOrder> orders = await db.GetProjectRentalOrders(this.ActiveCustomer,TheUser);

            IEnumerable <TrackUnitData> units = await db.GetTrackUnitData();

            IEnumerable <Transfer> transfers = projectsDB.GetCustomerTransfers(this.ActiveCustomer);

            model.CustomerTransfers = transfers;

            ViewBag.page = "MYPROJECTS";

            model.Orders = model.Process(orders, units, this.ActiveCustomer);

            List <TransferContact> projectContacts = new List <TransferContact>();

            orders.GroupBy(i => i.ContactPersonId).ToList().ForEach(i =>
            {
                RentalOrder machine = i.First();

                if (machine.ContactPerson != null && machine.ContactPersonEmail != null && machine.CustAccount != ActiveCustomer.CustomerId)
                {
                    projectContacts.Add(new TransferContact()
                    {
                        Id          = machine.ContactPersonId,
                        Name        = machine.ContactPerson,
                        Email       = machine.ContactPersonEmail,
                        CustomerId  = machine.CustAccount,
                        DisplayName = machine.AccountName
                    });
                }
            });

            model.TransferContacts = projectContacts.ToArray();

            return(View(model));
        }
        public async Task <PartialViewResult> GetProjects(ProjectsViewModel model)
        {
            //var orders = (await db.GetProjectRentalOrders(this.ActiveCustomer, TheUser));
            var orders = await GetOrders(this.ActiveCustomer, TheUser);

            IEnumerable <TrackUnitData> units = await db.GetTrackUnitData();

            var transfers = projectsDB.GetCustomerTransfers(this.ActiveCustomer);

            model.CustomerTransfers = transfers;

            model.Orders = model.Process(orders, units, this.ActiveCustomer);

            List <TransferContact> projectContacts = new List <TransferContact>();

            orders.GroupBy(i => i.ContactPersonId).ToList().ForEach(i =>
            {
                RentalOrder machine = i.First();

                if (machine.ContactPerson != null && machine.ContactPersonEmail != null && machine.CustAccount != ActiveCustomer.CustomerId)
                {
                    projectContacts.Add(new TransferContact()
                    {
                        Id          = machine.ContactPersonId,
                        Name        = machine.ContactPerson,
                        Email       = machine.ContactPersonEmail,
                        CustomerId  = machine.CustAccount,
                        DisplayName = machine.AccountName
                    });
                }
            });

            model.TransferContacts = projectContacts.ToArray();

            if (ActiveCustomer.projectsVersion == null)
            {
                return(PartialView("_ProjectsPartial_1", model));
            }
            else
            {
                return(PartialView("_ProjectsPartial_" + ActiveCustomer.projectsVersion, model));
            }
        }