예제 #1
0
        public async Task <IActionResult> SaveProject(ProjectViewModel projectViewModel)
        {
            projectViewModel.Tags = SerializeTags(projectViewModel.Tags);

            projectViewModel.ProjectStatus = projectViewModel.Status.ToString();

            string projectId;

            if (projectViewModel.Id == null)
            {
                var user = GetAuthenticatedUser();

                projectViewModel.AuthorId       = user.Email;
                projectViewModel.AuthorFullName = user.GetFullName();

                projectViewModel.Created           = DateTime.UtcNow;
                projectViewModel.ParticipantsCount = 0;

                projectId = await _projectRepository.SaveAsync(projectViewModel);

                if (_emailsQueue != null)
                {
                    var message = NotificationMessageHelper.ProjectCreatedMessage(user.Email, user.GetFullName(),
                                                                                  projectViewModel.Name);
                    await _emailsQueue.PutMessageAsync(message);
                }
            }
            else
            {
                var project = await _projectRepository.GetAsync(projectViewModel.Id);

                project.Status = (Status)Enum.Parse(typeof(Status), project.ProjectStatus, true);

                projectViewModel.LastModified = DateTime.UtcNow;

                projectId = projectViewModel.Id;

                await _projectRepository.UpdateAsync(projectViewModel);

                if (project.Status != Status.CompetitionRegistration && projectViewModel.Status == Status.CompetitionRegistration)
                {
                    await AddCompetitionMailToQueue(project);
                }

                if (project.Status != Status.Implementation && projectViewModel.Status == Status.Implementation)
                {
                    await AddImplementationMailToQueue(project);
                }

                if (project.Status != Status.Voting && projectViewModel.Status == Status.Voting)
                {
                    await AddVotingMailToQueue(project);
                }

                if (project.Status != Status.Archive && projectViewModel.Status == Status.Archive)
                {
                    await _winnersService.SaveWinners(projectViewModel.Id);
                }
            }

            await SaveProjectFile(projectViewModel.File, projectId);

            return(RedirectToAction("Index", "Home"));
        }