public async Task <IActionResult> SaveProject(ProjectViewModel projectViewModel, bool draft = false, bool enableVoting = false, bool enableRegistration = false) { projectViewModel.Tags = SerializeTags(projectViewModel.Tags); projectViewModel.ProjectStatus = projectViewModel.Status.ToString(); projectViewModel.SkipVoting = !enableVoting; projectViewModel.SkipRegistration = !enableRegistration; if (projectViewModel.CompetitionRegistrationDeadline == DateTime.MinValue) { projectViewModel.CompetitionRegistrationDeadline = DateTime.UtcNow.Date; } if (projectViewModel.VotingDeadline == DateTime.MinValue) { projectViewModel.VotingDeadline = DateTime.UtcNow.Date; } var idValid = Regex.IsMatch(projectViewModel.Id, @"^[a-z0-9-]+$") && !string.IsNullOrEmpty(projectViewModel.Id); if (!idValid) { ViewBag.ProjectCategories = _categoriesRepository.GetCategories(); ModelState.AddModelError("Id", "Project Url can only contain lowercase letters, numbers and the dash symbol and cannot be empty!"); return(View("CreateProject", projectViewModel)); } var project = await _projectRepository.GetAsync(projectViewModel.Id); if (project == null) { projectViewModel.Status = draft ? Status.Draft : Status.Initiative; var user = GetAuthenticatedUser(); projectViewModel.AuthorId = user.Email; projectViewModel.AuthorFullName = user.GetFullName(); projectViewModel.UserAgent = HttpContext.Request.Headers["User-Agent"].ToString(); projectViewModel.Created = DateTime.UtcNow; projectViewModel.ParticipantsCount = 0; var projectId = await _projectRepository.SaveAsync(projectViewModel); if (_emailsQueue != null) { var message = NotificationMessageHelper.ProjectCreatedMessage(user.Email, user.GetFullName(), projectViewModel.Name); await _emailsQueue.PutMessageAsync(message); } await SaveProjectFile(projectViewModel.File, projectId); return(RedirectToAction("ProjectDetails", "Project", new { id = projectId })); } ViewBag.ProjectCategories = _categoriesRepository.GetCategories(); ModelState.AddModelError("Id", "Project with that Project Url already exists!"); return(View("CreateProject", projectViewModel)); }
public Task ProduceSendEmailCommand <T>(string partnerId, string mailAddress, T msgData) where T : IEmailMessageData { var data = SendEmailData <T> .Create(partnerId, mailAddress, msgData); var msg = new QueueRequestModel <SendEmailData <T> > { Data = data }; return(_queueExt.PutMessageAsync(msg)); }
// TODO: These notification tasks should probably be done elsewhere - // I believe I saw that we've got additional requirements around notifications // coming up, so maybe a separate notification controller is in order private async Task AddCompetitionMailToQueue(IProjectData project) { var following = await GetProjectFollows(project.Id); foreach (var follower in following) { if (_emailsQueue != null) { var message = NotificationMessageHelper.GenerateCompetitionMessage(project, follower); await _emailsQueue.PutMessageAsync(message); } } }
public async Task <IActionResult> FollowProject(string id) { var user = GetAuthenticatedUser(); var project = await _projectRepository.GetAsync(id); var userAgent = HttpContext.Request.Headers["User-Agent"].ToString(); project.Status = StatusHelper.GetProjectStatusFromString(project.ProjectStatus); var sentMails = await _mailSentRepository.GetFollowAsync(); var match = sentMails.FirstOrDefault(x => x.ProjectId == id && x.UserId == user.Email); if (project.Status == Status.Initiative && match == null) { var initiativeMessage = NotificationMessageHelper.GenerateInitiativeMessage(project, user.GetFullName(), user.Email); await _emailsQueue.PutMessageAsync(initiativeMessage); await _mailSentRepository.SaveFollowAsync(user.Email, id); } var follow = await _projectFollowRepository.GetAsync(user.Email, id); if (follow == null) { await _projectFollowRepository.SaveAsync( new ProjectFollowEntity { UserId = user.Email, FullName = user.GetFullName(), ProjectId = id, UserAgent = userAgent }); } return(RedirectToAction("ProjectDetails", "Project", new { id })); }
public Task ProduceSendSmsCommand <T>(string partnerId, string phoneNumber, T msgData, bool useAlternativeProvider) { var msg = new SendSmsData <T> { PartnerId = partnerId, MessageData = msgData, PhoneNumber = phoneNumber, UseAlternativeProvider = useAlternativeProvider }; return(_queueExt.PutMessageAsync(msg)); }
public void OnException(ExceptionContext context) { var controller = context.RouteData.Values["controller"]; var action = context.RouteData.Values["action"]; _log.Error("LykkeStreams", context.Exception, context.Exception.Message, $"Controller: {controller}, action: {action}"); var message = new SlackMessage { Type = "Errors", //Errors, Info Sender = "Lykke Streams", Message = "Occured in: " + controller + "Controller, " + action + " - " + context.Exception.GetType() }; _slackMessageQueue.PutMessageAsync(message).Wait(); }
public override async Task TokenValidated(TokenValidatedContext context) { var email = context.Ticket.Principal.Claims.Where(c => c.Type == ClaimTypes.Email) .Select(c => c.Value).SingleOrDefault(); var sentMail = await _mailSentRepository.GetRegisterAsync(email); if (sentMail == null) { var firstName = context.Ticket.Principal.Claims.Where(c => c.Type == ClaimTypes.GivenName) .Select(c => c.Value).SingleOrDefault(); var message = NotificationMessageHelper.GenerateRegistrationMessage(firstName, email); await _emailsQueue.PutMessageAsync(message); await _mailSentRepository.SaveRegisterAsync(email); } await base.TokenValidated(context); }
public Task <string> PutMessageAsync(object itm) => WrapAsync(() => _impl.PutMessageAsync(itm), Name);