public CommunicationResponse UpdateShoppingItem([FromBody] UpdateShoppingItemRequest shoppingRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } ShoppingValidator.CheckIfValidItem(shoppingRequest); _shoppingRepository.UpdateItem(shoppingRequest); response.Notifications = new List <string> { $"The shopping item '{shoppingRequest.Name}' has been updated" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", shoppingRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", shoppingRequest); } return(response); }
public CommunicationResponse DeleteShoppingItem([FromBody] DeleteShoppingItemRequest deleteShoppingItemRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } _shoppingRepository.DeleteItem(deleteShoppingItemRequest.ShoppingItemId); response.Notifications = new List <string> { "The shopping item has been deleted" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", deleteShoppingItemRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", deleteShoppingItemRequest); } return(response); }
/// <summary> /// Creates the CommunicationResponse for Rock SMS Conversations /// </summary> /// <param name="fromPerson">From person.</param> /// <param name="messageKey">The message key.</param> /// <param name="toPersonAliasId">To person alias identifier.</param> /// <param name="message">The message.</param> /// <param name="rockSmsFromPhoneDv">From phone.</param> /// <param name="responseCode">The response code.</param> /// <param name="rockContext">The rock context.</param> private void CreateCommunicationResponse(Person fromPerson, string messageKey, int?toPersonAliasId, string message, DefinedValueCache rockSmsFromPhoneDv, string responseCode, Rock.Data.RockContext rockContext) { var smsMedium = EntityTypeCache.Get(SystemGuid.EntityType.COMMUNICATION_MEDIUM_SMS); var smsTransport = this.Transport.EntityType.Id; int?communicationId = null; if (fromPerson != null) { communicationId = GetCommunicationId(rockSmsFromPhoneDv, fromPerson.PrimaryAliasId.Value, 2); } var communicationResponse = new CommunicationResponse { MessageKey = messageKey, FromPersonAliasId = fromPerson?.PrimaryAliasId, ToPersonAliasId = toPersonAliasId, IsRead = false, RelatedSmsFromDefinedValueId = rockSmsFromPhoneDv.Id, RelatedCommunicationId = communicationId, RelatedTransportEntityTypeId = smsTransport, RelatedMediumEntityTypeId = smsMedium.Id, Response = message }; var communicationResposeService = new CommunicationResponseService(rockContext); communicationResposeService.Add(communicationResponse); rockContext.SaveChanges(); }
public CommunicationResponse UpdatePayment([FromBody] Core.Bills.Models.UpdatePaymentRequest paymentRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } PaymentValidator.CheckIfValidPayment(paymentRequest); _billRepository.UpdatePayment(paymentRequest); response.Notifications = new List <string> { "The payment has been updated" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", paymentRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", paymentRequest); } return(response); }
public async Task <IActionResult> UnsubscribePushNotification([FromBody] string DeviceID) { ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User); DeviceRegistrationRequest Request = new DeviceRegistrationRequest(); CommunicationResponse Response = new CommunicationResponse(); try { if (user == null) { Response.ReturnCode = enResponseCode.Fail; Response.ReturnMsg = EnResponseMessage.StandardLoginfailed; Response.ErrorCode = enErrorCode.StandardLoginfailed; } else { Request.DeviceID = DeviceID; Request.UserID = user.Id; Request.SubsscrptionType = EnDeviceSubsscrptionType.UnSubsscribe; Response = await _mediator.Send(Request); } return(Ok(Response)); } catch (Exception ex) { Response.ReturnCode = enResponseCode.InternalError; return(BadRequest(new BizResponseClass { ReturnCode = enResponseCode.InternalError, ReturnMsg = ex.ToString(), ErrorCode = enErrorCode.Status500InternalServerError })); } }
public void SetUp() { _subject = new CommunicationResponse(); _subject.AddError(new Error { UserMessage = "Some error message has occured." }); }
public override CommunicationResponse Request(CommunicationRequest parameter) { CommunicationResponse response = new CommunicationResponse(); try { string requestUrl = parameter.GetURL(); HttpWebRequest request = HttpWebRequest.Create(requestUrl) as HttpWebRequest; request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.ContentType = "application/x-AsyncWebClient"; request.Method = parameter.methodName; request.KeepAlive = false; request.ContentLength = parameter.dataLength; request.UserAgent = this.userAgent.Create(); request.Timeout = HttpCommunicationClient.TIME_OUT; if (parameter.methodName.Equals("POST")) { Stream streamRequest = request.GetRequestStream(); using (BinaryWriter byteWriter = new BinaryWriter(streamRequest)) { byteWriter.Write(parameter.GetQueryString()); byteWriter.Flush(); byteWriter.Close(); } } using (System.Net.HttpWebResponse webresponse = (HttpWebResponse)request.GetResponse()) { using (System.IO.Stream stream = webresponse.GetResponseStream()) { if (Regex.IsMatch(requestUrl, @"(\.html$|\.js$|\.xml|\.css|\.txt$)")) { using (System.IO.StreamReader reader = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8)) { string text = reader.ReadToEnd(); response.data = text; reader.Close(); } } else { using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream)) { response.data = reader.ReadBytes(1024 * 1000 * 10); reader.Close(); } } stream.Close(); } webresponse.Close(); } response.status = CommunicationResponse.ResponseStatus.SUCCESS; response.request = parameter; return(response); } catch (WebException we) { response.data = null; response.status = CommunicationResponse.ResponseStatus.FAILD; response.request = parameter; response.message = we.Message; Debug.LogError(we.Message); } return(response); }
public void SetUp() { _subject = new CommunicationResponse(); _subject.AddError(new Error { Code = 1, UserMessage = "Some user message", TechnicalMessage = "Some technical message" }); }
public override CommunicationResponse Request(CommunicationRequest parameter) { CommunicationResponse response = new CommunicationResponse(); Random random = new System.Random(); int sleepTime = random.Next(500, 4000); Thread.Sleep(sleepTime); response.request = parameter; return(response); }
public override Task <CommunicationResponse> GetAllChannels(CommunicationRequest request, ServerCallContext context) { var model = new CommunicationResponse(); model.Response.AddRange(mockModel); model.Total = mockModel.Count; context.Status = new Status(StatusCode.OK, $"ok"); return(Task.FromResult(model)); }
/// <summary> /// Creates the CommunicationResponse for Rock SMS Conversations /// </summary> /// <param name="fromPerson">From person.</param> /// <param name="messageKey">The message key.</param> /// <param name="toPersonAliasId">To person alias identifier.</param> /// <param name="message">The message.</param> /// <param name="rockSmsFromPhoneDv">From phone.</param> /// <param name="responseCode">The response code.</param> /// <param name="rockContext">The rock context.</param> /// <param name="attachments">The attachments.</param> /// <exception cref="System.Exception">Configuration Error. No SMS Transport Component is currently active.</exception> private void CreateCommunicationResponse(Person fromPerson, string messageKey, int?toPersonAliasId, string message, DefinedValueCache rockSmsFromPhoneDv, string responseCode, Rock.Data.RockContext rockContext, List <BinaryFile> attachments = null) { var smsMedium = EntityTypeCache.Get(SystemGuid.EntityType.COMMUNICATION_MEDIUM_SMS); if (this.Transport == null) { throw new Exception("Configuration Error. No SMS Transport Component is currently active."); } var smsTransport = this.Transport.EntityType.Id; int?communicationId = null; if (fromPerson != null) { communicationId = GetCommunicationId(rockSmsFromPhoneDv, fromPerson.PrimaryAliasId.Value, 2); } var communicationResponse = new CommunicationResponse { MessageKey = messageKey, FromPersonAliasId = fromPerson?.PrimaryAliasId, ToPersonAliasId = toPersonAliasId, IsRead = false, RelatedSmsFromDefinedValueId = rockSmsFromPhoneDv.Id, RelatedCommunicationId = communicationId, RelatedTransportEntityTypeId = smsTransport, RelatedMediumEntityTypeId = smsMedium.Id, Response = message }; var communicationResposeService = new CommunicationResponseService(rockContext); communicationResposeService.Add(communicationResponse); rockContext.SaveChanges(); // Now that we have a communication response ID we can add the attachments if (attachments != null && attachments.Any()) { foreach (var attachment in attachments) { communicationResponse.Attachments.Add( new CommunicationResponseAttachment { BinaryFileId = attachment.Id, CommunicationResponseId = communicationResponse.Id, CommunicationType = CommunicationType.SMS } ); } rockContext.SaveChanges(); } }
public async Task <IActionResult> SendEmail(SendEmailRequest Request) { try { CommunicationResponse Response = await _mediator.Send(Request); return(Ok(Response)); } catch (Exception ex) { return(BadRequest(Response)); } }
public async Task <IActionResult> SendMessage([FromBody] SendSMSRequest Request) { try { CommunicationResponse Response = await _mediator.Send(Request); return(Ok(Response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
/// <summary> /// return communication information by user id /// </summary> /// <param name="userid">User Id</param> /// <returns>Task<CommunicationResponse> </returns> public async Task <CommunicationResponse> GetByUserIdAsync(long userid) { IEnumerable <Communication> com = await _communicationRepository.GetByUserIdAsync(userid); var response = new CommunicationResponse(); if (com.ToList().Count == 0) { response.Message = "Kayıt bulunamadı !"; } else { response.Communications.AddRange(com); } return(response); }
public CommunicationResponse DeleteHousehold([FromBody] DeleteHouseholdRequest deleteHouseholdRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } string sessionId = Request.Headers["Authorization"].ToString(); ActiveUser user = _userService.GetUserInformationFromAuthHeader(sessionId); if (user.HouseId == 0) { response.AddError("You must belong to a household", ErrorCode.USER_NOT_IN_HOUSEHOLD); return(response); } _billRepository.DeleteHouseholdBills(user.HouseId); _shoppingRepository.DeleteHouseholdShoppingItems(user.HouseId); _toDoRepository.DeleteHouseholdToDoTask(user.HouseId); if (deleteHouseholdRequest.KeepHousehold == false) { _houseRepository.DeleteHousehold(user.HouseId); _userService.DeleteSession(sessionId); _userService.UpdateHouseholdForUser(sessionId, -1); } response.Notifications = new List <string> { $"The data for the household (ID: {user.HouseId}) have been deleted" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", deleteHouseholdRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", deleteHouseholdRequest); } return(response); }
public CommunicationResponse AddShoppingItem([FromBody] AddShoppingItemRequest shoppingRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString()); if (user.HouseId == 0) { response.AddError("You must belong to a household to add shopping items", ErrorCode.USER_NOT_IN_HOUSEHOLD); return(response); } ShoppingItem item = new ShoppingItem { ItemFor = shoppingRequest.ItemFor, Added = DateTime.Now, AddedBy = user.PersonId, Name = shoppingRequest.Name, Purchased = false }; ShoppingValidator.CheckIfValidItem(item); _shoppingRepository.AddItem(item, user.HouseId); response.Notifications = new List <string> { $"The shopping item '{shoppingRequest.Name}' has been added" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", shoppingRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", shoppingRequest); } return(response); }
public CommunicationResponse DeleteBill([FromBody] DeleteBillRequest deleteBillRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString()); if (user.HouseId == 0) { response.AddError("You must belong to a household to delete bills", ErrorCode.USER_NOT_IN_HOUSEHOLD); return(response); } var rowUpdated = _billRepository.DeleteBill(deleteBillRequest.BillId); if (rowUpdated == false) { response.AddError($"Cannot delete the bill (ID: {deleteBillRequest.BillId}) because it does not exist"); return(response); } response.Notifications = new List <string> { $"The bill (ID: {deleteBillRequest.BillId}) has been deleted" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", deleteBillRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", deleteBillRequest); } return(response); }
private void AsyncRequest(object parameter) { CommunicationRequest reqparam = parameter as CommunicationRequest; BaseCommunicationClient client = CommunicationClientFactory.FactoryMethod(reqparam.clientType); client.userAgent = this.userAgent; if (null == client) { return; } CommunicationResponse response = client.Request(reqparam); lock (reqparam) { if (response.status == CommunicationResponse.ResponseStatus.SUCCESS) { reqparam.callback.OnSuccessCallback(response); } else { reqparam.callback.OnFaildCallback(response); } } }
public async Task <IActionResult> EmailWithTemplateForSample([FromBody] SendEmailRequest Request) { try { string GeneratedLink = "https://cleandevtest.azurewebsites.net/SSO_Account/api/SignUp/ConfirmEmail?emailConfirmCode=mLjgF4N8iwzW2z4fs7dUSmEgAO1M3GziSngzVkS2UV9JAk1SUnCUoinNXm3SjGmcFlA6Tqp7wJTShohQ89Snbx3aastoWzItNncfTqf9dGqUNPPaCWAyumi%2B3FbcG1Jrh%2F8eRPznAZ%2BXKrwNDWz3JSniADZ4eDRE4e9mKbTk9rmc3OieMKv7nsco43TFOdkqsEqis%2Bxj5dKoPGx%2Bsk%2FWQnuhTl3j7u%2FtByvBIGT3c3EwgbyIlTdO6hR5ZIMG1JwZwRQ7Tl6UjlJBFc3AGMTAI7aRWN0LZNTjqcSJ6UzpKZhHt5%2FKhF8qdtP13S0HnNnt%2B2rpBVpve9Aw4t1R9Wez0aQn38axHNQhBwBSgqnDg0I%3D"; IQueryable Result = await _messageConfiguration.GetTemplateConfigurationAsync(Convert.ToInt16(enCommunicationServiceType.Email), Convert.ToInt16(EnTemplateType.Registration), 0); foreach (TemplateMasterData Provider in Result) { //string[] splitedarray = Provider.AdditionaInfo.Split(","); //foreach (string s in splitedarray) //{ Provider.Content = Provider.Content.Replace("#Link#", GeneratedLink); Provider.Content = Provider.Content.Replace("###USERNAME###", "Khushali"); Provider.Content = Provider.Content.Replace("###TYPE###", "LTCBTC"); Provider.Content = Provider.Content.Replace("###REQAMOUNT###", "100000"); Provider.Content = Provider.Content.Replace("###STATUS###", "Success"); Provider.Content = Provider.Content.Replace("###USER###", "Khushali"); Provider.Content = Provider.Content.Replace("###CURRENCY###", "BTC"); Provider.Content = Provider.Content.Replace("###DATETIME###", "4 Nov 2018 12:39 PM"); Provider.Content = Provider.Content.Replace("###AMOUNT###", "100000"); Provider.Content = Provider.Content.Replace("###FEES###", "1000"); Provider.Content = Provider.Content.Replace("###FINAL###", "101000"); //} Request.Body = Provider.Content; } CommunicationResponse Response = await _mediator.Send(Request); return(Ok(Response)); } catch (Exception ex) { return(BadRequest(Response)); } }
public CommunicationResponse DeletePayment([FromBody] DeletePaymentRequest paymentRequest) { var response = new CommunicationResponse(); try { if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false) { response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID); return(response); } var rowUpdated = _billRepository.DeletePayment(paymentRequest.PaymentId); if (rowUpdated == false) { response.AddError($"Cannot delete the payment (ID: {paymentRequest.PaymentId}) because it does not exist"); return(response); } response.Notifications = new List <string> { $"The payment (ID: {paymentRequest.PaymentId}) has been deleted" }; } catch (ErrorCodeException exception) { response.AddError($"An unexpected exception occured: {exception}", paymentRequest, exception.Code); } catch (Exception exception) { response.AddError($"An unexpected exception occured: {exception}", paymentRequest); } return(response); }
public virtual void OnFaild(CommunicationResponse response) { return; }
public virtual void OnSuccess(CommunicationResponse response) { return; }