public IActionResult Get(string id) { using (var conn = factory.CreateConnection()) using (var channel = conn.CreateModel()) { channel.ExchangeDeclare("psw", ExchangeType.Direct, true); channel.QueueBind("psw-special-offers-queue", "psw", "psw.specialoffers"); var data = channel.BasicGet("psw-special-offers-queue", false); if (data == null) { return(BadRequest("No data")); } var msg = Encoding.UTF8.GetString(data.Body.ToArray()); channel.BasicAck(data.DeliveryTag, false); PharmacyNotification pharmacyNotification = _notificationService.Add(msg); if (pharmacyNotification == null) { return(NotFound()); } else { return(Ok(pharmacyNotification)); } } }
public PharmacyNotification Add(string recivedNotification) { PharmacyNotification pharmacyNotification = ParseNotification(recivedNotification); pharmacyNotification.Id = getNextId(); if (CheckPermisionToSendNotification(pharmacyNotification.PharmacyId)) { return(_pharmacyNotificationRepository.Create(pharmacyNotification)); } return(null); }
public IActionResult Post(PharmacyNotification pharmacyNotification) { bool isSuccessfullyAdded = _notificationService.Update(pharmacyNotification) != null; if (isSuccessfullyAdded) { return(Ok()); } else { return(BadRequest()); } }
private PharmacyNotification ParseNotification(string recivedNotification) { string content; string pharmacyId; try { dynamic data = JsonConvert.DeserializeObject(recivedNotification); content = data.content; pharmacyId = data.pharmacyId; } catch (Exception) { content = "Failed to parse content!"; pharmacyId = " "; } PharmacyNotification pharmacyNotification = new PharmacyNotification(content, pharmacyId); return(pharmacyNotification); }
public PharmacyNotification Update(PharmacyNotification pharmacyNotification) => _pharmacyNotificationRepository.Update(pharmacyNotification);
public bool Remove(PharmacyNotification pharmacy) => _pharmacyNotificationRepository.Delete(pharmacy);