示例#1
0
        // GET: /Employee/Read/Id
        /// <summary>
        /// Gets all employees by specified criteria from database.
        /// </summary>
        /// <param name="Id">Page number for employee list.</param>
        /// <param name="text">Filter text for employee list.</param>
        /// <param name="option">Filter by option for employee list.</param>
        /// <returns>
        /// Indicator which says if returns succesfully.
        /// Amount of employees returned.
        /// List of employees and List of employees' gross values.
        /// </returns>
        public ActionResult Read(int?Id, string text, string option)
        {
            List <Employee> employees       = null;                   // List of employees to return
            List <decimal>  grossValues     = new List <decimal>();   // For every employee to return holds his gross salary
            GrossCalculator grossCalculator = new GrossCalculator();  // Class to calculate gross salary

            if (Id == null)
            {
                Id = 1;
            }

            if (text == null || option == null)
            {
                employees = db.Employees.OrderBy(x => x.Name).ToList();
            }
            else
            {
                // Choosing how to take data from database
                switch (option)
                {
                case "1":
                    employees = db.Employees.Where(x => x.Name.Contains(text)).OrderBy(x => x.Name).ToList();
                    break;

                case "2":
                    employees = db.Employees.Where(x => x.LastName.Contains(text)).OrderBy(x => x.Name).ToList();
                    break;

                default:
                    employees = db.Employees.OrderBy(x => x.Name).ToList();
                    break;
                }
            }

            int size = employees.Count;
            int from = (Id.Value - 1) * MAX_PER_PAGE;

            if (from > size)
            {
                return(RedirectToAction("Index", "Error"));
            }

            int amount = (size - from < MAX_PER_PAGE) ? size - from : MAX_PER_PAGE;

            // Taking employees only for specified page
            employees = employees.GetRange(from, amount);

            // Calculating GROSS value for every employee
            foreach (Employee e in employees)
            {
                grossValues.Add(grossCalculator.CalculateGross(e.Net, 1, 0, 1, false, null));
            }

            return(Json(new { success = employees.Any(), size = size, employees, grossValues }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        // GET: /Employee/Calculate
        /// <summary>
        /// Calculate a Gross salary and other expenses.
        /// </summary>
        /// <param name="net">Given Net salary</param>
        /// <param name="npdOption">
        /// If system should calculate NPD or user
        ///   1 - system, 2 - user
        /// </param>
        /// <param name="kidsAmount">Amount of kids that user has</param>
        /// <param name="growKids">If kids are grown alone or by two people
        ///    1 - alone, 2 - two people
        /// </param>
        /// <param name="isTwoPercent">If paid 2 more percent for pension then true</param>
        /// <param name="customNpd">Given custom NPD if npdOption is 2</param>
        /// <returns>Returns salary and expenses</returns>
        public ActionResult Calculate(decimal net, int npdOption, int?kidsAmount, int?growKids,
                                      bool isTwoPercent, decimal?customNpd)
        {
            GrossCalculator grossCalculator = new GrossCalculator();

            grossCalculator.CalculateGross(net, npdOption, kidsAmount, growKids, isTwoPercent, customNpd);
            grossCalculator.CalculateOtherParameters(isTwoPercent);
            grossCalculator.RoundParemeters();

            return(Json(grossCalculator, JsonRequestBehavior.AllowGet));
        }