示例#1
0
        public ActionResult RemainingBudget()
        {
            string username = User.Identity.Name;

            Student student         = _repository.Query <Student>().Include("Project").Include("Orders").SingleOrDefault(i => i.UserProfile.UserName == username); // retrieve user and load project and orders entities in advance
            var     budget          = student.Project.Budget;
            var     totalOrdersCost = _calculator.TotalCost(student);
            var     project         = student.Project;

            if (student.Project == null) // If the studen't hasn't entered project information then redirect student to enter project details as without project details you can't view the remaining budget
            {
                return(RedirectToAction("RequestComponents"));
            }

            ProjectSpendView viewModel = new ProjectSpendView(); // Initilise the viewmodel and pass relevant object information to view objects members

            viewModel.Budget          = budget;
            viewModel.TotalOrdersCost = totalOrdersCost;
            viewModel.SpendLeft       = budget - totalOrdersCost; // Show budget if supervisor approved order
            viewModel.Project         = project;

            viewModel = PieChartForProjectSpendViewModel(viewModel); // create the piechart by passing current viewmodel to the piechart method

            return(View(viewModel));                                 // send the object to the view
        }
示例#2
0
        /* Method which creates a pie chart from the provided viewmodel object information*/
        public ProjectSpendView PieChartForProjectSpendViewModel(ProjectSpendView viewModel)
        {
            Highcharts pieChart = new Highcharts("pieChart")
                                  .InitChart(new Chart {
                PlotShadow = false, Width = 500, Height = 500
            })                                                                          // Size parameters
                                  .SetTitle(new Title {
                Text = "Budget"
            })                                                    // sets the title of pie chart
                                  .SetPlotOptions(new PlotOptions // sets plot options
            {
                Pie = new PlotOptionsPie
                {
                    AllowPointSelect = true,
                    Cursor           = Cursors.Pointer,
                    DataLabels       = new PlotOptionsPieDataLabels
                    {
                        Color          = ColorTranslator.FromHtml("#000000"),
                        ConnectorColor = ColorTranslator.FromHtml("#000000"),
                    }
                }
            })
                                  .SetSeries(new Series // sets series information
            {
                Type = ChartTypes.Pie,
                Name = "Budget",
                Data = new Data(new object[]
                {
                    new DotNet.Highcharts.Options.Point
                    {
                        Name     = "Budget",
                        Y        = (double)viewModel.Budget,
                        Selected = true,
                        Color    = Color.LightGreen
                    },

                    new DotNet.Highcharts.Options.Point
                    {
                        Name     = "Budget If Pending Orders Approved",
                        Y        = (double)viewModel.SpendLeft,
                        Sliced   = true,
                        Color    = Color.LightBlue,
                        Selected = true
                    },
                })
            });


            viewModel.PieChart = pieChart; // passes it to view model object

            return(viewModel);             // returns viewmodel
        }
示例#3
0
        public ActionResult ProjectSpend()
        {
            string  username  = User.Identity.Name;
            Student student   = _repository.Query <Student>().Include("Orders.Components").Include("Project").SingleOrDefault(i => i.UserProfile.UserName == username); // Eager loading used to retrieve student object
            var     viewModel = new ProjectSpendView();                                                                                                                 // Initilise the viewmodel and pass relevant object information to view objects members

            if (student.Project == null)                                                                                                                                // collect project details if they are not saved
            {
                return(RedirectToAction("RequestComponents"));
            }

            viewModel.Orders = _orderInformation.GetApprovedOrders(student);
            viewModel.Budget = student.Project.Budget;

            viewModel.TotalOrdersCost = _orderInformation.GetTotalOrdersCost(student.Orders); // use sum function to calculate the total cost of all orders for student.orders object

            viewModel = BarChartForProjectSpendViewModel(viewModel);                          // // create the piechart by passing current viewmodel to the piechart method


            return(View(viewModel));
        }
示例#4
0
        /* Method which creates a bar chart from the provided viewmodel object information*/
        public ProjectSpendView BarChartForProjectSpendViewModel(ProjectSpendView viewModel)
        {
            List <Component> components = new List <Component>(); // creates list to store component objects

            /* Method which adds components within orders which are approved to the list*/
            foreach (Order o in viewModel.Orders)
            {
                if (o.IsApproved == true)
                {
                    components.AddRange(o.Components);
                }
            }

            var pricesList   = new List <object>(); // a price list to store prices
            var categoryList = new List <string>(); // a category list to store categories

            /* Method to add prices of components to the pricelist and the names of components in categories */
            foreach (Component c in components)
            {
                pricesList.Add(new object[] { c.Price });
                categoryList.Add(c.Name);
            }

            object[] prices     = pricesList.ToArray();   /* Creates array and passes information from prices list to array*/
            string[] categories = categoryList.ToArray(); /* Creates category array and passes categories list to array */


            Highcharts barChart = new Highcharts("barChart") //Initalises barchart
                                  .InitChart(new Chart {
                DefaultSeriesType = ChartTypes.Column, Margin = new[] { 50, 50, 100, 80 }, Width = 400, Height = 300
            })                                                                                                                                 // Size parameters
                                  .SetTitle(new Title {
                Text = "Purchases"
            })                                        // sets the title of chart
                                  .SetXAxis(new XAxis // sets the x axis information
            {
                Categories = categories,
                Labels     = new XAxisLabels
                {
                    Rotation = -45,
                    Align    = HorizontalAligns.Right,
                    Style    = "font: 'normal 13px Verdana, sans-serif'"
                }
            })
                                  .SetYAxis(new YAxis // sets the y axis information
            {
                Min   = 0,
                Max   = (double)viewModel.Budget + (double)viewModel.TotalOrdersCost,
                Title = new YAxisTitle {
                    Text = "Cost"
                }
            })
                                  .SetLegend(new Legend {
                Enabled = false
            })
                                  .SetSeries(new Series // sets series information
            {
                Name = "Price",
                Data = new Data(prices),
            });

            viewModel.BarChart = barChart; // passes it to viewmodel object

            return(viewModel);             // returns a view model
        }