public async Task <IActionResult> PutEmployee(int id, Employee employee) { if (id != employee.EmployeeId) { return(BadRequest()); } _context.Entry(employee).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> AddGroup(GenericGroup item) { _context.GenericGroups.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("GroupsList")); }
public async Task <IActionResult> PutDepartment(int id, Department department) { if (id != department.DepartmentId) { return(BadRequest()); } _context.Entry(department).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> AddOrgUnit(OrgUnit item, long?parentId) { //calculate ou code if (!parentId.HasValue) //new company { item.Code = "01"; } else { string parentCode = _context.OrgUnits.SingleOrDefault(b => b.Id == parentId).Code; int seq = _context.OrgUnits.Where(b => b.Code.StartsWith(parentCode) && b.Code.Length == parentCode.Length + 3).Count() + 1; if (seq < 10) { item.Code = parentCode + "." + "0" + seq.ToString(); } else { item.Code = parentCode + "." + seq.ToString(); } } item.IsVacant = true; item.CreatedDate = DateTime.Now.Date; item.LastUpdated = DateTime.Now.Date; item.UpdatedBy = "user"; _context.OrgUnits.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("OrgChart", new { id = parentId })); }
public async Task <IActionResult> AddAttendance(Attendance item) { await _context.Attendances.AddAsync(item); await _context.SaveChangesAsync(); return(RedirectToAction("AttendancesList")); }
public async Task <IActionResult> AddCarouselItem(CarouselItem item) { item.LastUpdated = DateTime.Now.Date; item.UpdatedBy = "user"; _context.CarouselItems.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("CarouselItemsList")); }
public async Task <IActionResult> EditHead(OrgUnit item, int?ouTypeId) { var model = await _context.OrgUnits.SingleOrDefaultAsync(b => b.Id == item.Id); await TryUpdateModelAsync(model); model.LastUpdated = DateTime.Now.Date; model.UpdatedBy = "user"; await _context.SaveChangesAsync(); return(RedirectToAction("HeadsList", new { id = ouTypeId })); }
public async Task <IActionResult> AddShift(Shift item) { await _context.Shifts.AddAsync(item); await _context.SaveChangesAsync(); return(RedirectToAction("ShiftsList")); }
public async Task <IActionResult> AddCalendar(Calendar item) { _context.Calendars.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("CalendarsList")); }
public async Task <IActionResult> AddPayroll(Payroll item) { item.LastUpdated = DateTime.Now.Date; item.UpdatedBy = "user"; _context.Payrolls.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("PayrollsList")); }
public async Task <IActionResult> EditContacts(Employee item) { var model = await _context.Employees.SingleOrDefaultAsync(b => b.Id == item.Id); await TryUpdateModelAsync(model); model.LastUpdated = DateTime.Now.Date; model.UpdatedBy = "user"; await _context.SaveChangesAsync(); return(Content("Thank You for Updating Your Contacts.", "text/html")); }
public async Task <IActionResult> AddCompany(OrgUnit item, string ShortName, string OthShortName, string LegalTypeCode, long?CalendarId) { int orgUnitTypeId = _lookup.GetLookupItems <OrgUnitType>().SingleOrDefault(b => b.SysCode == "COMPANY").Id; int cnt = await _context.OrgUnits.Where(b => b.OrgUnitTypeId == orgUnitTypeId).CountAsync() + 1; if (cnt > 9) { item.Code = cnt.ToString(); } else { item.Code = "0" + cnt.ToString(); } item.OrgUnitTypeId = orgUnitTypeId; item.SortOrder = 1; item.IsVacant = true; item.IsActive = true; item.CreatedDate = DateTime.Now.Date; item.LastUpdated = DateTime.Now.Date; item.UpdatedBy = "user"; await _context.OrgUnits.AddAsync(item); //add company entity Company comp = new Company(); comp.Id = item.Id; comp.LegalTypeCode = LegalTypeCode; comp.ShortName = ShortName; comp.OthShortName = OthShortName; comp.CalendarId = CalendarId; await _context.Companies.AddAsync(comp); await _context.SaveChangesAsync(); return(RedirectToAction("CompaniesList")); }
public async Task <IActionResult> EditEmployee(Employee item) { var model = await _context.Employees.Include(b => b.Governorate).Include(b => b.Nationality).SingleOrDefaultAsync(b => b.Id == item.Id); await TryUpdateModelAsync(model); model.LastUpdated = DateTime.Now.Date; model.UpdatedBy = "user"; await _context.SaveChangesAsync(); return(PartialView("_PersonalData", model)); }
public async Task <IActionResult> AddGradeGroup(GradeGroup item) { int cnt = await _context.GradeGroups.CountAsync(); item.Code = "G" + (cnt + 1).ToString(); item.SortOrder = (cnt + 1) * 10; _context.GradeGroups.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("GradeGroupsList")); }
//void to create employee from AddEmployee or HireCandidate actions private async void CreateEmployee(Employee item, long orgUnitId, int employmentTypeId, DateTime?dateInPosition, long?positionId, int?jobGradeId, int?salaryStepId, int?salaryScaleTypeId, int basicSalary = 0, bool isHead = false, bool isProbation = false) { if (string.IsNullOrEmpty(item.EmpUid)) { item.EmpUid = (int.Parse(_context.Employees.Max(b => b.EmpUid)) + 1).ToString(); } item.IsActive = true; item.LastUpdated = DateTime.Now.Date; item.UpdatedBy = "user"; _context.Employees.Add(item); Employment pos = new Employment(); pos.OrgUnitId = orgUnitId; pos.EmployeeId = item.Id; pos.IsHead = isHead; pos.PositionId = positionId; if (positionId.HasValue) { var p = await _context.Positions.SingleOrDefaultAsync(b => b.Id == positionId); pos.IsAttendRequired = p.IsAttendRequired; pos.IsOverTimeAllowed = p.IsOverTimeAllowed; } pos.EmploymentTypeId = employmentTypeId; pos.JobGradeId = jobGradeId; pos.SalaryStepId = salaryStepId; pos.SalaryScaleTypeId = salaryScaleTypeId; pos.BasicSalary = basicSalary; pos.FromDate = dateInPosition.HasValue ? dateInPosition.Value : DateTime.Now.Date; pos.IsActive = true; pos.IsProbation = isProbation; _context.Employments.Add(pos); //add initial hiring as promotion EmployeePromotion prom = new EmployeePromotion(); prom.EmploymentId = pos.Id; prom.PromotionTypeId = _lookup.GetLookupItems <PromotionType>().SingleOrDefault(b => b.SysCode == "INIT").Id; prom.JobGradeId = jobGradeId; prom.SalaryStepId = salaryStepId; prom.BasicSalary = basicSalary; prom.CreatedDate = DateTime.Now.Date; prom.EffectiveFromDate = dateInPosition.HasValue ? dateInPosition.Value : DateTime.Now.Date; prom.IsApproved = true; prom.LastUpdated = DateTime.Now.Date; prom.UpdatedBy = "user"; _context.EmployeePromotions.Add(prom); //add leave entitlements int annualTypeId = _lookup.GetLookupItems <LeaveType>().SingleOrDefault(b => b.SysCode == "ANNUAL").Id; int sickTypeId = _lookup.GetLookupItems <LeaveType>().SingleOrDefault(b => b.SysCode == "SICK").Id; int entitle = 0; if (jobGradeId.HasValue) { int grpId = _context.JobGrades.SingleOrDefault(b => b.Id == jobGradeId).Id; var lv = _context.LeavePolicies.SingleOrDefault(b => b.LeaveTypeId == annualTypeId && (b.JobGradeId == jobGradeId || b.GradeGroupId == grpId)); if (lv != null) { entitle = lv.TotalDays; } } _context.EmployeeLeaveBalances.Add(new EmployeeLeaveBalance { EmployeeId = item.Id, LeaveTypeId = annualTypeId, AnnualEntitlement = entitle }); entitle = 0; if (jobGradeId.HasValue) { int grpId = _context.JobGrades.SingleOrDefault(b => b.Id == jobGradeId).Id; var lv = _context.LeavePolicies.SingleOrDefault(b => b.LeaveTypeId == sickTypeId && (b.JobGradeId == jobGradeId || b.GradeGroupId == grpId)); if (lv != null) { entitle = lv.TotalDays; } } _context.EmployeeLeaveBalances.Add(new EmployeeLeaveBalance { EmployeeId = item.Id, LeaveTypeId = sickTypeId, AnnualEntitlement = entitle }); //update vacancies if (isHead) { _context.OrgUnits.SingleOrDefault(b => b.Id == orgUnitId).IsVacant = false; } else { var p = await _context.Positions.SingleOrDefaultAsync(b => b.Id == positionId); if (p.TotalVacant > 0) { p.TotalVacant--; } } await _context.SaveChangesAsync(); }