示例#1
0
        public ActionResult DeleteBranch(DeleteEntityViewModel branchToDelete)
        {
            var user   = _context.userRepository.GetUserByEmail(this.User.Identity.Name);
            var branch = _context.branchRepository.GetBranchById(branchToDelete.EntityIdentificator);

            if (branch == null)
            {
                return(RedirectToAction("UniversalConfirmationPanel", "Account", new { messageNumber = 6, returnUrl = Url.BlankMenuLink(Request.Scheme) }));
            }

            if (ModelState.IsValid && _keyGenerator.ValidateUserTokenForEntityDeletion(user, branchToDelete.Code))
            {
                _context.branchRepository.DeleteBranch(branchToDelete.EntityIdentificator);

                #region EntityLogs

                var logInfoDeleteBranch = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[2], LogDescriptions.DescriptionOfActionOnEntity["deleteBranch"]);

                var logInfoUpdateCertificate = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[1], LogDescriptions.DescriptionOfActionOnEntity["updateCertificate"]);
                var logInfoUpdateDegree      = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[1], LogDescriptions.DescriptionOfActionOnEntity["updateDegree"]);
                var logInfoUpdateCourse      = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[1], LogDescriptions.DescriptionOfActionOnEntity["updateCourse"]);

                _logger.AddBranchLog(branch, logInfoDeleteBranch);

                var updatedCourses = _context.courseRepository.DeleteBranchFromCourses(branch.BranchIdentificator);
                _logger.AddCoursesLogs(updatedCourses, logInfoUpdateCourse);

                var updatedCertificates = _context.certificateRepository.DeleteBranchFromCertificates(branch.BranchIdentificator);
                _logger.AddCertificatesLogs(updatedCertificates, logInfoUpdateCertificate);

                var updatedDegrees = _context.degreeRepository.DeleteBranchFromDegrees(branch.BranchIdentificator);
                _logger.AddDegreesLogs(updatedDegrees, logInfoUpdateDegree);

                #endregion

                #region PersonalUserLogs

                var logInfoPersonal = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["deleteBranch"], "Nazwa: " + branch.Name);
                _context.personalLogRepository.AddPersonalUserLogToAdminGroup(logInfoPersonal);

                #endregion

                return(RedirectToAction("DisplayAllBranches", "Branches", new { message = "Usunięto wskazany obszar certyfikacji" }));
            }

            return(View("DeleteEntity", branchToDelete));
        }