public IActionResult Create(DeploymentCreateViewModel deployment) { if (!ModelState.IsValid) { return(View()); } var newDeployment = _handler.CreateDeployment(deployment, User); return(CreateRedirect(newDeployment)); }
private void CheckCreateConflicts(DeploymentCreateViewModel deployment) { bool conflictAlreadyLinkedGitAndFtp = _unitOfWork.Deployments.Any(x => x.GitUrl == deployment.GitUrl && x.GitBranch == deployment.GitBranch && x.FtpHostname == deployment.FtpHostname && x.FtpRootDirectory == deployment.FtpRootDirectory); if (conflictAlreadyLinkedGitAndFtp) { throw new Exception("Git and FTP host already linked."); } }
public Deployment CreateDeployment(DeploymentCreateViewModel deployment, ClaimsPrincipal user) { var userId = _userManager.GetUserAsync(user).Result; CheckCreateConflicts(deployment); var newDeployment = new Deployment() { User = userId, FtpHostname = deployment.FtpHostname, FtpPassword = deployment.FtpPassword, FtpPort = deployment.FtpPort, FtpUsername = deployment.FtpUsername, GitBranch = deployment.GitBranch, GitUrl = deployment.GitUrl, FtpRootDirectory = deployment.FtpRootDirectory, State = DeploymentState.WaitingForPingEvent }; _unitOfWork.Deployments.Add(newDeployment); newDeployment.Logs.Add(new DeploymentLog() { Description = "Created", Status = ResultStatus.Successful, DateTime = DateTime.Now, EventType = "create", ResultMessage = string.Empty, }); _unitOfWork.Complete(); _communicator.Bus.Publish(new IntegrationCreateEvent() { FtpHostname = newDeployment.FtpHostname, FtpPassword = newDeployment.FtpPassword, FtpPort = newDeployment.FtpPort, FtpUsername = newDeployment.FtpUsername, GitBranch = newDeployment.GitBranch, GitUrl = newDeployment.GitUrl, FtpRootDirectory = newDeployment.FtpRootDirectory, IntegrationGuid = newDeployment.Guid }); return(newDeployment); }