public async Task <IActionResult> DeleteOld(int id)
        {
            if (_signInManager.Context.User.Identity.IsAuthenticated)
            {
                if (HttpContext.User.IsInRole("Hr"))
                {
                    if (id == 0)
                    {
                        return(BadRequest());
                    }
                    OldWork oldWork = await _db.OldWorks
                                      .Where(ow => ow.Id == id)
                                      .Include(ow => ow.Employee)
                                      .FirstOrDefaultAsync();

                    if (oldWork == null)
                    {
                        ModelState.AddModelError("", "This work places couldn't find");
                        return(BadRequest());
                    }
                    _db.OldWorks.Remove(oldWork);
                    await _db.SaveChangesAsync();

                    return(Redirect("/Payroll/Work/Works/" + oldWork.EmployeeId));
                }
            }
            return(RedirectToAction("Forbidden", "Error"));
        }
        public async Task <IActionResult> EditOld(OldWorkModel oldWorkModel)
        {
            if (_signInManager.Context.User.Identity.IsAuthenticated)
            {
                if (HttpContext.User.IsInRole("Hr"))
                {
                    await Initializer.InitialLayout("Work Places", ViewBag, _db, _signInManager, "Old/Edit");

                    if (ModelState.IsValid)
                    {
                        OldWork ow = await _db.OldWorks
                                     .Where(dbow => dbow.Id == oldWorkModel.Id)
                                     .Include(dbow => dbow.Employee)
                                     .FirstOrDefaultAsync();

                        if (ow == null)
                        {
                            ModelState.AddModelError("", "This work places couldn't find");
                            return(View(oldWorkModel));
                        }
                        ow.HoldingName    = oldWorkModel.HoldingName;
                        ow.BranchName     = oldWorkModel.BranchName;
                        ow.CompanyName    = oldWorkModel.CompanyName;
                        ow.DepartmentName = oldWorkModel.DepartmentName;
                        ow.PositionName   = oldWorkModel.PositionName;
                        ow.EnterTime      = oldWorkModel.EnterTime;
                        ow.LeaveTime      = oldWorkModel.LeaveTime;
                        ow.Reason         = oldWorkModel.Reason;
                        await _db.SaveChangesAsync();

                        return(Redirect("/Payroll/Work/Works/" + ow.EmployeeId));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Something is wrong. Please try again");
                        return(View(oldWorkModel));
                    }
                }
            }
            return(RedirectToAction("Forbidden", "Error"));
        }
        public async Task <IActionResult> AddOld(OldWorkModel owm)
        {
            if (_signInManager.Context.User.Identity.IsAuthenticated)
            {
                if (HttpContext.User.IsInRole("Hr"))
                {
                    await Initializer.InitialLayout("Work Places", ViewBag, _db, _signInManager, "Add Old work places");

                    if (ModelState.IsValid)
                    {
                        OldWork ow = new OldWork
                        {
                            HoldingName    = owm.HoldingName,
                            CompanyName    = owm.CompanyName,
                            BranchName     = owm.BranchName,
                            DepartmentName = owm.DepartmentName,
                            PositionName   = owm.PositionName,
                            EnterTime      = owm.EnterTime,
                            LeaveTime      = owm.LeaveTime,
                            Reason         = owm.Reason,
                            EmployeeId     = owm.EmployeeId
                        };
                        await _db.OldWorks.AddAsync(ow);

                        await _db.SaveChangesAsync();

                        return(Redirect("/Payroll/Work/Works/" + owm.EmployeeId));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Something is wrong. Please try again");
                        return(View(owm));
                    }
                }
            }
            return(RedirectToAction("Forbidden", "Error"));
        }