Exemplo n.º 1
0
 public ActionResult Save(int id, Employee employee)
 {
     if (!ModelState.IsValid)
     {
         return(View("Edit", employee));
     }
     if (id != employee.Id)
     {
         return(BadRequest());
     }
     using (var db = new nominaDBContext())
     {
         if (id == 0)
         {
             db.Employee.Add(employee);
         }
         else
         {
             var employeeInDb = db.Employee.Find(id);
             employeeInDb.Name        = employee.Name;
             employeeInDb.LastName    = employee.LastName;
             employeeInDb.Genre       = employee.Genre;
             employeeInDb.GrossSalary = employee.GrossSalary;
             employeeInDb.Active      = employee.Active;
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 2
0
        // GET: Employees/Delete/5
        public ActionResult Delete(int id)
        {
            if (id != 0)
            {
                using (var db = new nominaDBContext())
                {
                    var employee = db.Employee.Find(id);
                    db.Employee.Remove(employee);

                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
        // GET: Payroll/Delete/5
        public ActionResult Delete(int id)
        {
            if (id != 0)
            {
                using (var db = new nominaDBContext())
                {
                    var nominaInDb = db.Payroll.Find(id);
                    db.Payroll.Remove(nominaInDb);

                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Save(Payroll payroll)
        {
            if (!ModelState.IsValid)
            {
                using (var db = new nominaDBContext())
                {
                    var viewModel = new PayrollViewModel()
                    {
                        employeeList = db.Employee.Include(e => e.Payroll).Where(e => e.Payroll.Count() == 0 && e.Active).ToList(),
                        Payroll      = payroll
                    };
                    return(View("Edit", viewModel));
                }
            }


            using (var db = new nominaDBContext())
            {
                var employeeInDb   = db.Employee.Find(payroll.EmployeeId);
                var afp            = Convert.ToDouble(employeeInDb.GrossSalary) * 0.0287;
                var ars            = Convert.ToDouble(employeeInDb.GrossSalary) * 0.0304;
                var taxableSalary  = employeeInDb.GrossSalary - Convert.ToDecimal((afp + ars));
                var isr            = calculateISR(Convert.ToDouble(taxableSalary));
                var retentionTotal = afp + ars + isr;

                var newPayroll = new Payroll()
                {
                    EmployeeId     = payroll.EmployeeId,
                    GrossSalary    = employeeInDb.GrossSalary,
                    RetentionAfp   = afp,
                    RetentionArs   = ars,
                    TaxableSalary  = taxableSalary,
                    RetentionIsr   = isr,
                    RetentionTotal = retentionTotal,
                    NetIncome      = employeeInDb.GrossSalary - Convert.ToDecimal(retentionTotal)
                };

                db.Payroll.Add(newPayroll);

                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }