public ActionResult DeleteDegree(DeleteEntityViewModel degreeToDelete) { var user = _context.userRepository.GetUserByEmail(this.User.Identity.Name); var degree = _context.degreeRepository.GetDegreeById(degreeToDelete.EntityIdentificator); if (degree == null) { return(RedirectToAction("UniversalConfirmationPanel", "Account", new { messageNumber = 6, returnUrl = Url.BlankMenuLink(Request.Scheme) })); } if (ModelState.IsValid && _keyGenerator.ValidateUserTokenForEntityDeletion(user, degreeToDelete.Code)) { #region EntityLogs var logInfoDeleteDegree = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[2], LogDescriptions.DescriptionOfActionOnEntity["deleteDegree"]); var logInfoDeleteGivenDegrees = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[1], LogDescriptions.DescriptionOfActionOnEntity["deleteGivenDegree"]); var logInfoDeleteRequiredDegreeFromGivenDegrees = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[2], LogDescriptions.DescriptionOfActionOnEntity["deleteRequiredDegreeFromDegree"]); var logInfoUpdateUsers = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[1], LogDescriptions.DescriptionOfActionOnEntity["deleteUserGivenDegree"]); _context.degreeRepository.DeleteDegree(degreeToDelete.EntityIdentificator); _logger.AddDegreeLog(degree, logInfoDeleteDegree); var degreesWhichHasDeletedRequiredDegree = _context.degreeRepository.DeleteRequiredDegreeFromDegree(degreeToDelete.EntityIdentificator); _logger.AddDegreesLogs(degreesWhichHasDeletedRequiredDegree, logInfoDeleteDegree); var deletedGivenDegrees = _context.givenDegreeRepository.DeleteGivenDegreesByDegreeId(degreeToDelete.EntityIdentificator); _logger.AddGivenDegreesLogs(deletedGivenDegrees, logInfoDeleteGivenDegrees); var updatedUsers = _context.userRepository.GetUsersByGivenDegreesId(deletedGivenDegrees.Select(z => z.GivenDegreeIdentificator).ToList()); _logger.AddUsersLogs(updatedUsers, logInfoUpdateUsers); #endregion #region PersonalLogs var logInfoPersonalDeleteDegree = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["deleteDegree"], "Indekser: " + degree.DegreeIndexer); _context.personalLogRepository.AddPersonalUserLogToAdminGroup(logInfoPersonalDeleteDegree); foreach (var deletedGivenDegree in deletedGivenDegrees) { var logInfoPersonalDeleteGivenDegree = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["deleteGivenDegree"], "Indekser: " + deletedGivenDegree.GivenDegreeIndexer); _context.personalLogRepository.AddPersonalUserLogToAdminGroup(logInfoPersonalDeleteGivenDegree); var deletedGivenDegreeOwner = _context.userRepository.GetUserByGivenDegreeId(deletedGivenDegree.GivenDegreeIdentificator); var logInfoPersonalDeleteUserGivenDegree = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["deleteUserGivenDegree"], "Indekser: " + deletedGivenDegree.GivenDegreeIndexer); _context.personalLogRepository.AddPersonalUserLog(deletedGivenDegreeOwner.Id, logInfoPersonalDeleteUserGivenDegree); } foreach (var degreeWhichHasDeletedRequiredDegree in degreesWhichHasDeletedRequiredDegree) { var logInfoPersonalUpdateDegree = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["deleteRequiredDegree"], "Indekser: " + degreeWhichHasDeletedRequiredDegree.DegreeIndexer); _context.personalLogRepository.AddPersonalUserLogToAdminGroup(logInfoPersonalUpdateDegree); var givenDegrees = _context.givenDegreeRepository.GetGivenDegreesByIdOfDegree(degreeWhichHasDeletedRequiredDegree.DegreeIdentificator); foreach (var givenDegree in givenDegrees) { var ownerOfGivenDegree = _context.userRepository.GetUserByGivenDegreeId(givenDegree.GivenDegreeIdentificator); var logInfoPersonalUpdateUserGivenDegree = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["updateUserGivenDegree"], "Indekser: " + givenDegree.GivenDegreeIndexer); _context.personalLogRepository.AddPersonalUserLog(ownerOfGivenDegree.Id, logInfoPersonalUpdateUserGivenDegree); } } #endregion return(RedirectToAction("DisplayAllDegrees", "Degrees", new { message = "Usunięto wskazany stopień zawodowy" })); } return(View("DeleteEntity", degreeToDelete)); }