public async Task <IActionResult> EditSupportUnit(int id, SupportUnit unit, List <int> employeeIds, List <int> systemIds) { var supportUnit = _organizationService.GetSupportUnit(id); var oldValue = JsonConvert.SerializeObject(supportUnit, Formatting.Indented); supportUnit.Name = unit.Name; supportUnit.Email = unit.Email; _organizationService.SaveChanges(); var newValue = JsonConvert.SerializeObject(supportUnit, Formatting.Indented); var identity = (ClaimsIdentity)User.Identity; await _auditLog.Append(identity.GetClaimAsInt("EmployeeId"), LogActionType.Update, LogResourceType.SupportUnit, supportUnit.SupportUnitId, $"{identity.GetClaim(ClaimTypes.Name)} updated support unit with id {supportUnit.SupportUnitId}", oldValue, newValue); var employees = _userService.GetEmployees(employeeIds); foreach (var employee in employees) { employee.SupportUnitId = supportUnit.SupportUnitId; } _userService.SaveChanges(); var systems = _systemService.GetSystems(systemIds); foreach (var system in systems) { system.SupportUnitId = supportUnit.SupportUnitId; } _systemService.SaveChanges(); return(RedirectToAction(nameof(ViewSupportUnit), new { id })); }
public async Task <IActionResult> AddSupportUnit(SupportUnit unit, List <int> employeeIds, List <int> systemIds) { unit = _organizationService.AddSupportUnit(unit); var employees = _userService.GetEmployees(employeeIds); foreach (var employee in employees) { employee.SupportUnitId = unit.SupportUnitId; } _userService.SaveChanges(); var systems = _systemService.GetSystems(systemIds); foreach (var system in systems) { system.SupportUnitId = unit.SupportUnitId; } _systemService.SaveChanges(); var identity = (ClaimsIdentity)User.Identity; await _auditLog.Append(identity.GetClaimAsInt("EmployeeId"), LogActionType.Create, LogResourceType.SupportUnit, unit.SupportUnitId, $"{identity.GetClaim(ClaimTypes.Name)} created support unit with id {unit.SupportUnitId}"); return(RedirectToAction(nameof(ViewSupportUnit), new { id = unit.SupportUnitId })); }
public SupportUnit AddSupportUnit(SupportUnit unit) { _dbContext.SupportUnits.Add(unit); _dbContext.SaveChanges(); return(unit); }