/// <summary> /// Create recipient with first name, last name, and email. /// </summary> /// <param name="recipientCreateRequest"> /// request object that contains the parameters for using the api method of Interchecks Api Create Recipients /// </param> /// <returns> /// response object Recipient Created /// </returns> public async Task <RecipientDTO> CreateRecipient(RecipientCreateRequest recipientCreateRequest) { if (recipientCreateRequest == null) { throw new ArgumentNullException(nameof(recipientCreateRequest)); } else { var urlRequest = $"{_interchecksApiSettings.Value.ApiRecipientsCreateCall}/{_interchecksApiSettings.Value.PayerId}"; HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(recipientCreateRequest).ToString(), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(urlRequest, httpContent); if (response.IsSuccessStatusCode) { RecipientDTO recipientDTO = JsonConvert.DeserializeObject <RecipientDTO>(response.Content.ReadAsStringAsync().Result); return(recipientDTO); } else { string respError = response.Content.ReadAsStringAsync().Result; InterchecksApiError apiError = JsonConvert.DeserializeObject <InterchecksApiError>(respError); _logger.LogError($"Interchecks Api Error, Error Code:{apiError.ErrorCode}:{apiError.ErrorMessage}"); return((RecipientDTO)IntercheckApiErrorHandler.Handle(apiError)); } } }
public async Task <IActionResult> Post(RecipientDTO model) { RecipientModel recipient = new DTOMapper <RecipientDTO, RecipientModel>().Serialize(model); var Response = await _recipientService.AddRecipients(recipient); return(Ok(Response)); }
/// <summary> /// Get recipient using the recipient ID. /// </summary> /// <param name="recipient_id"> /// Recipient id /// </param> /// <returns> /// response object Recipient /// </returns> public async Task <RecipientDTO> GetRecipientById(string recipientId) { if (String.IsNullOrEmpty(recipientId)) { return(null); } else { var urlRequest = $"{_interchecksApiSettings.Value.ApiRecipientsGetCall.Replace("{{PayerId}}", _interchecksApiSettings.Value.PayerId).Replace("{{RecipientId}}", recipientId)}"; var response = await _httpClient.GetAsync(urlRequest); if (response.IsSuccessStatusCode) { RecipientDTO recipientDTO = JsonConvert.DeserializeObject <RecipientDTO>(response.Content.ReadAsStringAsync().Result); return(recipientDTO); } else { string respError = response.Content.ReadAsStringAsync().Result; InterchecksApiError apiError = JsonConvert.DeserializeObject <InterchecksApiError>(respError); _logger.LogError($"Interchecks Api Error, Error Code:{apiError.ErrorCode}:{apiError.ErrorMessage}"); return((RecipientDTO)IntercheckApiErrorHandler.Handle(apiError)); } } }
public int DisplayPlaceInQueue(RecipientDTO _recipientDto) { var _recipientQueue = _recipientService.GetRecipientssWithConcretBloodGroup(_recipientDto.BloodGroup); int placeInQueue = _recipientQueue.FindIndex(a => a.RecipientId == _recipientDto.RecipientId); Console.WriteLine($"Twoje aktualne miejsce w kolejce oczekujących na donacje krwi: {placeInQueue}"); return(placeInQueue); }
internal static void Notify(UserDTO sender, RecipientDTO recipient, NotificationDTO notification, bool requirePush = true, string pushPreview = "") { var hubContext = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); var userConnection = ChatHub._connections.GetConnection(recipient.Id); if (!userConnection.PushMode) { switch (notification.Type) { case (int)NotificationTypeEnum.Photo: case (int)NotificationTypeEnum.Audio: case (int)NotificationTypeEnum.Video: case (int)NotificationTypeEnum.VoiceNote: if (!string.IsNullOrEmpty(notification.Group)) { hubContext.Clients.Client(userConnection.ConnectionId).GroupMediaReceived(notification.Group, notification.Type, notification.Id, notification.Content, sender.Id, notification.SizeInBytes, notification.Duration, notification.IssuedAt.ToString(ChatUtils.DATE_TIME_FORMAT), notification.IsScrambled, notification.ExpiresAt); } else { if (!string.IsNullOrEmpty(notification.ExpiresAt)) { hubContext.Clients.Client(userConnection.ConnectionId).TemporaryMediaReceived(notification.Type, notification.Id, notification.Content, sender.Id, notification.SizeInBytes, notification.ExpiresAt, notification.Duration, notification.IssuedAt.ToString(ChatUtils.DATE_TIME_FORMAT), notification.IsScrambled); } else { hubContext.Clients.Client(userConnection.ConnectionId).MediaReceived(notification.Type, notification.Id, notification.Content, sender.Id, notification.SizeInBytes, notification.Duration, notification.IssuedAt.ToString(ChatUtils.DATE_TIME_FORMAT), notification.IsScrambled); } } break; default: if (!string.IsNullOrEmpty(notification.Group)) { hubContext.Clients.Client(userConnection.ConnectionId).GroupMessageReceived(notification.Group, notification.Type, notification.Id, notification.Content, sender.Id, notification.ExpiresAt, notification.IsScrambled, notification.IssuedAt); } else { if (!string.IsNullOrEmpty(notification.ExpiresAt)) { hubContext.Clients.Client(userConnection.ConnectionId).TemporaryMessageReceived(notification.Type, notification.Id, notification.Content, sender.Id, notification.ExpiresAt, notification.IsScrambled, notification.IssuedAt.ToString(ChatUtils.DATE_TIME_FORMAT)); } else { hubContext.Clients.Client(userConnection.ConnectionId).MessageReceived(notification.Type, notification.Id, notification.Content, sender.Id, notification.IsScrambled, notification.IssuedAt.ToString(ChatUtils.DATE_TIME_FORMAT)); } } break; } } else { if (requirePush) { Task.Factory.StartNew(() => PushManager.Send(pushPreview, recipient.UserId, recipient.Id, sender.Name, sender.Id, notification.Group)); } } }
public void AddToDb(ref RecipientDTO recipientDto) { var Recipient = new Recipient(); Recipient = Mapper.Map <Recipient>(recipientDto); context.RecipientTab.Add(Recipient); context.SaveChanges(); recipientDto.RecipientId = Recipient.RecipientId; }
private RecipientDTO RecipientToDTO(Recipient entity) { var model = new RecipientDTO(); model.Id = entity.Id; model.CreationDate = entity.CreationDate; model.Email = entity.Email; model.GroupNames = entity.RecipientInGroups.Select(rig => rig.Group.Name).ToList(); return(model); }
public async Task <IHttpActionResult> Get(string id, string message) { var sender = new UserDTO { }; var recipient = new RecipientDTO { Id = id }; var notification = new NotificationDTO { Content = message }; ChatUtils.Notify(sender, new List <RecipientDTO> { recipient }, notification); return(Ok()); }
public void Report_hop_should_return_true() { var hop = new HopArrivalModel { Code = "1234", DateTime = DateTime.Now, TrackingId = "12345ABC" }; var recipient = new RecipientDTO { FirstName = "Rudi", LastName = "Recipient", Street = "Poststraße", PostalCode = "A-1070", City = "Poststadt" }; var parcel = new ParcelDTO { Recipient = recipient, Weight = 1.0f, TrackingCode = "MOCKCODE" }; var ware = new WarehouseDTO { Code = "1234", Description = "root warehouse", Duration = 12, Id = 3 }; var truck = new TruckDTO { Code = "1234", Description = "root truck", Duration = 42, Id = 4 }; truckMock.Setup(input => input.GetByCode(It.IsAny <string>())).Returns(truck); warehouseMock.Setup(input => input.GetByCode(It.IsAny <string>())).Returns(ware); parcelMock.Setup(input => input.GetByTrackingCode(It.IsAny <string>())).Returns(parcel); var result = tracking.ReportHop(hop); // Assert Assert.IsTrue(result); }
public void FindMatch(RecipientDTO _recipientDto) { var _donersList = _donerService.GetDonersWithConcretBloodGroup(_recipientDto.BloodGroup); Console.WriteLine($"Znaleziono {_donersList.Count} dawców:"); if (_donersList.Count > 0) { foreach (var Doner in _donersList) { Console.WriteLine($"Imie: {Doner.FirstName}, Nazwisko: {Doner.LastName}, Grupa Krwi: {Doner.BloodGroup}, Wiek: {Doner.Age}, Miejsce oddania krwi: {Doner.Location}"); } var donerToDelete = ChoosYourDoner(_donersList); _recipientService.RemoveFromDb(_recipientDto.RecipientId); _donerService.RemoveFromDb(donerToDelete.DonerId); } else { Console.WriteLine($"W tym momencie nie posiadamy krwi o grupie {_recipientDto.BloodGroup}"); } }
public void Get_Parcel_by_code_should_return_Parcel() { // Arrange var recipient = new RecipientDTO() { FirstName = "Rudi", LastName = "Recipient", Street = "Poststraße", PostalCode = "A-1070", City = "Poststadt" }; var parcel = new ParcelDTO() { Recipient = recipient, Weight = 1.0f, TrackingCode = "MOCKCODE" }; parcelMock.Setup(input => input.GetByTrackingCode(It.IsAny <string>())).Returns(parcel); var result = tracking.GetParcelByCode("MOCKCODE"); // Assert Assert.IsInstanceOfType(result, typeof(ParcelModel)); }
/// <summary> /// First search a recipient by email, if Recimpient doesn't exist then /// this method create a recipient with first name, last name, and email /// if Recimpient does exist will be returned /// </summary> /// <param name="recipientCreateRequest"> /// request object that contains the parameters for using the api method of Interchecks Api Search and Create Recipients /// </param> /// <returns> /// response object Recipient Searched or Created /// </returns> public async Task <RecipientDTO> CreateIntegralRecipient(RecipientCreateRequest recipientCreateRequest) { if (recipientCreateRequest == null) { throw new ArgumentNullException(nameof(recipientCreateRequest)); } else { RecipientSearchRequest recipientSearchRequest = _mapper.Map <RecipientSearchRequest>(recipientCreateRequest); RecipientDTO recipientSearched = await this.SearchRecipient(recipientSearchRequest); if (recipientSearched == null) { RecipientDTO recipientCreated = await this.CreateRecipient(recipientCreateRequest); return(recipientCreated); } else { return(recipientSearched); } } }
public RecipientDTO SignIn() { string _firstName = string.Empty, _lastName = string.Empty, _bloodGroup = string.Empty, _illness = string.Empty; int _risk = 0, _age = 0; try { GetUserData(ref _firstName, ref _lastName, ref _bloodGroup, ref _illness, ref _risk, ref _age); } catch (UserDataException _dataException) { Console.WriteLine($"Źle podane dane, {_dataException.Message}"); } catch (RiskException _riskException) { Console.WriteLine($"Źle podany poziom zapotrzebowania na krew {_riskException.Message}"); } var newRecipient = new RecipientDTO(_firstName, _lastName, _age, _bloodGroup, _risk, _illness); _recipientService.AddToDb(ref newRecipient); return(newRecipient); }