Пример #1
0
        //This method is called asynchronously to calculate wages.
        public IActionResult OnPostCalculate()
        {
            var emploeeId = Convert.ToInt32(Request.Query["emploeeId"]);
            var emploee   = _context.Emploees.FirstOrDefault(p => p.ID == emploeeId);

            // This is the calculation for non-fixed employees.
            if (!emploee.FIX_PAYMENT)
            {
                var salaryamount = _calculate.Consider(emploee.F_NAME, emploee.L_NAME);
                CalculateResult[0] = emploee.FIX_PAYMENT;
                CalculateResult[2] = emploee.F_NAME;
                CalculateResult[3] = emploee.L_NAME;
                CalculateResult[5] = salaryamount;
                CalculateResult[6] = emploee.COUNT_HOUR;
                return(new JsonResult(CalculateResult));
            }
            // This is the calculation for fixed employees.
            else
            {
                //This is the validation of data from calendars.
                var firstdate        = Request.Query["firstdate"];
                var lastdate         = Request.Query["lastdate"];
                var validationresult = Validation.DateValidation(firstdate, lastdate);
                CalculateResult[0] = true;
                CalculateResult[1] = validationresult[0];
                CalculateResult[4] = validationresult[1];
                if (!Convert.ToBoolean(validationresult[0]))
                {
                    return(new JsonResult(CalculateResult));
                }

                // This is the calculation for fixed employees.
                var FirstDate    = Convert.ToDateTime(firstdate);
                var LastDate     = Convert.ToDateTime(lastdate);
                var salaryamount = _calculate.ConsiderFix(emploee.F_NAME, emploee.L_NAME, FirstDate, LastDate);
                CalculateResult[0] = emploee.FIX_PAYMENT;
                CalculateResult[2] = emploee.F_NAME;
                CalculateResult[3] = emploee.L_NAME;
                CalculateResult[5] = salaryamount[0];
                CalculateResult[6] = salaryamount[1];
                return(new JsonResult(CalculateResult));
            }
        }