public ActionResult AddNewGivenCertificate(AddGivenCertificateViewModel newGivenCertificate) { if (ModelState.IsValid) { GivenCertificate givenCertificate = _mapper.Map <GivenCertificate>(newGivenCertificate); givenCertificate.GivenCertificateIdentificator = _keyGenerator.GenerateNewId(); givenCertificate.Course = _context.courseRepository.GetCourseById(newGivenCertificate.SelectedCourse).CourseIdentificator; var certificate = _context.certificateRepository.GetCertificateById(newGivenCertificate.SelectedCertificate); givenCertificate.Certificate = certificate.CertificateIdentificator; givenCertificate.GivenCertificateIndexer = _keyGenerator.GenerateGivenCertificateEntityIndexer(certificate.CertificateIndexer); _context.givenCertificateRepository.AddGivenCertificate(givenCertificate); _context.userRepository.AddUserCertificate(newGivenCertificate.SelectedUser, givenCertificate.GivenCertificateIdentificator); var user = _context.userRepository.GetUserById(newGivenCertificate.SelectedUser); #region EntityLogs var logInfoAddGivenCertificate = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[0], LogDescriptions.DescriptionOfActionOnEntity["addGivenCertificate"]); _logger.AddGivenCertificateLog(givenCertificate, logInfoAddGivenCertificate); var logInfoUpdateUser = _logger.GenerateLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogTypeOfAction.TypesOfActions[1], LogDescriptions.DescriptionOfActionOnEntity["addUserGivenCertificate"]); _logger.AddUserLog(user, logInfoUpdateUser); #endregion #region PersonalUserLogs var logInfoPersonalAddGivenCertificate = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["addGivenCertificate"], "Indekser: " + givenCertificate.GivenCertificateIndexer); _context.personalLogRepository.AddPersonalUserLogToAdminGroup(logInfoPersonalAddGivenCertificate); var logInfoPersonalAddGivenCertificateToUser = _context.personalLogRepository.GeneratePersonalLogInformation(this.User.Identity.Name, this.ControllerContext.RouteData.Values["action"].ToString(), LogDescriptions.DescriptionOfPersonalUserLog["addUserGivenCertificate"], "Indekser: " + givenCertificate.GivenCertificateIndexer); _context.personalLogRepository.AddPersonalUserLog(user.Id, logInfoPersonalAddGivenCertificateToUser); #endregion return(RedirectToAction("ConfirmationOfActionOnGivenCertificate", new { givenCertificateIdentificator = givenCertificate.GivenCertificateIdentificator, TypeOfAction = "Add" })); } newGivenCertificate.AvailableCertificates = _context.certificateRepository.GetCertificatesAsSelectList().ToList(); newGivenCertificate.AvailableUsers = _context.userRepository.GetUsersAsSelectList().ToList(); newGivenCertificate.AvailableCourses = _context.courseRepository.GetActiveCoursesAsSelectList().ToList(); return(View(newGivenCertificate)); }