Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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());
        }
Esempio n. 6
0
        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.");
            }
        }
Esempio n. 7
0
 public IHttpActionResult Enqueue(AnuntDto anunt)
 {
     PushQueue.Enqueue(anunt);
     return(Ok());
 }
Esempio n. 8
0
 public static void Enqueue(AnuntDto anunt)
 {
     _pushQueue.Enqueue(anunt);
 }