Beispiel #1
0
        //logic to find out who is the top seller of the currect month
        public static string getTopSeller()
        {
            CurrentMonthSale result = new CurrentMonthSale();
            foreach (var record in currentMonthSales)
            {
                foreach (var guy in record.Employees)
                {
                    bool containsEmployee = result.Employees.Any(emp => emp.EmpName == guy.EmpName);

                    if (!containsEmployee)
                    {
                        result.EmployeesList.Add(guy);
                    }
                    else
                    {
                        result.EmployeesList.Find(emp => emp.EmpName == guy.EmpName).Amount += guy.Amount;
                    }
                }
            }
            IEmployee highestSeller = new Employee();
            if (result.EmployeesList.Count > 0)
            {
            highestSeller = result.EmployeesList[0];
            foreach (var guy in result.EmployeesList)
            {
                if (highestSeller.Amount < guy.Amount)
                {
                    highestSeller = guy;
                }
            }
            }
            else
            {
                highestSeller.EmpName = "John Smith";
                highestSeller.NameInitials = "JS";
                highestSeller.Amount = -1;
            }

            return highestSeller.EmpName;
        }
Beispiel #2
0
 //Get values from the endpoint. check if the data is valid. If valid set the new values in the controller.
 public void setCurrentMonthSales()
 {
     var result = dd.GetCurrentMonthSaleStatistics();
     if (result.GetType() == typeof(List<CurrentMonthSale>))
     {
         currentMonthSales = new List<ICurrentMonthSale>();
         foreach (var item in result)
         {
             currentMonthSales.Add(item);
         }
         if (currentMonthSales.Count < 31)
         {
             for (int i = currentMonthSales.Count; i < 31; i++)
             {
                 ICurrentMonthSale dummySale = new CurrentMonthSale();
                 dummySale.Total = 0;
                 currentMonthSales.Add(dummySale);
             }
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Transform the string from the enpoint into a list of CurrentMonthSale objects
        /// </summary>
        /// <returns>List or error</returns>
        public dynamic GetCurrentMonthSaleStatistics()
        {
            string json = conn.GetCurrentMonthSale();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            List<CurrentMonthSale> currentMonthSales = new List<CurrentMonthSale>();

            try
            {
                var result = jss.Deserialize<JsonReturnedObj>(json);
                foreach (var yearly_month in result.result)
                {
                    CurrentMonthSale monthSale = new CurrentMonthSale();
                    List<IEmployee> employees = new List<IEmployee>();

                    string yearMonthDate = yearly_month.Key;
                    foreach (var employee in yearly_month.Value)
                    {

                        if (employee.Key != "total")
                        {
                            Employee emp = new Employee();

                            emp.NameInitials = employee.Key;
                            emp.EmpName = employee.Value["name"];
                            emp.Amount = employee.Value["amount"];
                            employees.Add(emp);
                        }

                    }
                    monthSale.EmployeesList = employees;
                    monthSale.SaleDay = DateTime.Parse(yearMonthDate);
                    monthSale.Total = yearly_month.Value["total"];
                    currentMonthSales.Add(monthSale);
                }

            }
            catch (Exception)
            {

                Error err = new Error();

                err.Error_Msg = "Service unavailable";
                err.Error_Number = -1;

                return err;
            }

            return currentMonthSales;
        }