public IHttpActionResult PublishMany(IList <AnuntModel> anunturi) { foreach (var anunt in anunturi) { try { var dto = new AnuntDto() { Content = anunt.Content, Subject = anunt.Subject, Role = anunt.Role }; var anuntId = _anuntService.AddAnunt(dto); var pushInfo = new PushInfo() { Id = anuntId, Subject = dto.Subject }; _signalRHelper.NotifyAnunturiForRole(pushInfo, dto.Role); } catch (Exception) { // log exception } } return(Ok()); }
private static void SendMessagesToApiWorker() { while (true) { try { var listToSend = new List <AnuntDto>(); while (!_pushQueue.IsEmpty) { var anunt = new AnuntDto(); if (_pushQueue.TryDequeue(out anunt)) { listToSend.Add(anunt); } } if (listToSend.Any()) { _anuntApi.PublishAnunt(listToSend); } } catch (Exception e) { // Logger } finally { Thread.Sleep(DELAY_TIME); } } }
public AnuntDto GetAnuntWithRole(int anuntId) { var anunt = _anuntDal.GetAnuntWithRole(anuntId); var result = new AnuntDto() { Content = anunt.Content, Id = anunt.Id, Subject = anunt.Subject, Role = anunt.Role.Name }; return(result); }
public int AddAnunt(AnuntDto dto) { var role = _roleManager.Roles.Where(x => x.Name == dto.Role).FirstOrDefault(); var anunt = new Anunt() { Content = dto.Content, Subject = dto.Subject, Role = role, Created = DateTime.Now }; _anuntRepo.Insert(anunt); _anuntRepo.Save(); return(anunt.Id); }
public IHttpActionResult Publish(AnuntModel model) { if (ModelState.IsValid) { var dto = new AnuntDto() { Content = model.Content, Subject = model.Subject, Role = model.Role }; var anuntId = _anuntService.AddAnunt(dto); var pushInfo = new PushInfo() { Id = anuntId, Subject = dto.Subject }; _signalRHelper.NotifyAnunturiForRole(pushInfo, dto.Role); return(Ok()); } return(BadRequest()); }
private async Task PublishAnuntAsync() { var html = HtmlEditor.ContentHtml; var subject = SubjectTextBox.Text; var role = RoleList.Text; if (!string.IsNullOrWhiteSpace(html) && !string.IsNullOrWhiteSpace(subject) && !string.IsNullOrWhiteSpace(role)) { var anunt = new AnuntDto() { Content = html, Subject = subject, Role = role }; await _anuntQueueApi.Enqueue(anunt); this.Close(); } else { MessageBox.Show("Introdu subiectul, rolul si continutul."); } }
public IHttpActionResult Enqueue(AnuntDto anunt) { PushQueue.Enqueue(anunt); return(Ok()); }
public static void Enqueue(AnuntDto anunt) { _pushQueue.Enqueue(anunt); }