Beispiel #1
0
        public async Task <IActionResult> SendText(SendTextViewModel vm)
        {
            var token = _weixinAccessToken.GetToken();
            await Custom.SendText(token, vm.OpenId, vm.Content);

            return(Ok());
        }
Beispiel #2
0
        public HttpResponseMessage SendText(SendTextViewModel viewModel)
        {
            //TODO replace this with proper user id from ASPNet Identity
            viewModel.UserId    = this.UserId;
            viewModel.AccountID = this.AccountId;
            SendTextRequest request = new SendTextRequest()
            {
                SendTextViewModel = viewModel
            };
            SendTextRequest ServiceProviderRequest = new SendTextRequest
            {
                UserId    = this.UserId,
                AccountId = this.AccountId
            };

            SendTextViewModel ServiceProviderViewmodel = communicationService.GetSendTextviewModel(ServiceProviderRequest).SendTextViewModel;

            request.SendTextViewModel.ServiceProvider = ServiceProviderViewmodel.ServiceProvider;
            SendTextResponse response = communicationService.SendText(request);

            if (response.SMSStatus == "Success")
            {
                response.Message = "Sent successfully";
            }
            else
            {
                if (response.Exception != null)
                {
                    response.Message = response.Exception.Message;
                }
            }

            return(Request.BuildResponse(response));
        }
        //saves message that was sent in real time in the controller.
        public bool SendMessage(SendTextViewModel textInfo, String user_id)
        {
            var _unitOfWork = new UnitOfWork();
            var query       = _unitOfWork.AccountRepository.FirstOrDefault(x => x.gordon_id == user_id);

            if (query == null)
            {
                throw new ResourceNotFoundException()
                      {
                          ExceptionMessage = "The account was not found."
                      };
            }

            var idParam        = new SqlParameter("@_id", textInfo.id);
            var roomIdParam    = new SqlParameter("@room_id", textInfo.room_id);
            var textParam      = new SqlParameter("@text", textInfo.text);
            var createdAtParam = new SqlParameter("@createdAt", textInfo.createdAt);
            var userIdParam    = new SqlParameter("@user_id", user_id);
            var imageParam     = new SqlParameter("@image", System.Data.SqlDbType.VarBinary, -1);
            var videoParam     = new SqlParameter("@video", System.Data.SqlDbType.VarBinary, -1);
            var audioParam     = new SqlParameter("@audio", System.Data.SqlDbType.VarBinary, -1);
            var systemParam    = new SqlParameter("@system", textInfo.system);
            var sentParam      = new SqlParameter("@sent", textInfo.sent);
            var receivedParam  = new SqlParameter("@received", textInfo.received);
            var pendingParam   = new SqlParameter("@pending", textInfo.pending);

            imageParam.Value = DBNull.Value;
            videoParam.Value = DBNull.Value;
            audioParam.Value = DBNull.Value;

            if (textInfo.image != null)
            {
                byte[] decodedByteArray = Convert.FromBase64CharArray(textInfo.image.ToCharArray(), 0, textInfo.image.Length);
                imageParam.Value = decodedByteArray;
            }


            var result = RawSqlQuery <SendTextViewModel> .query("INSERT_MESSAGE @_id, @room_id, @text, @createdAt, @user_id, @image, @video, @audio, @system, @sent, @received, @pending",
                                                                idParam, roomIdParam, textParam, createdAtParam, userIdParam, imageParam, videoParam, audioParam, systemParam, sentParam, receivedParam, pendingParam); //run stored procedure

            var UpdateRoomIdParam = new SqlParameter("@room_id", textInfo.room_id);
            var updateRoom        = RawSqlQuery <SendTextViewModel> .query("UPDATE_ROOM  @room_id", UpdateRoomIdParam); //run stored procedure

            bool returnAnswer = true;

            if (result == null)
            {
                returnAnswer = false;
                throw new ResourceNotFoundException()
                      {
                          ExceptionMessage = "The data was not found."
                      };
            }

            return(returnAnswer);
        }
Beispiel #4
0
        public async Task refreshMessages(List <string> userIds, SendTextViewModel message, string userId)
        {
            DirectMessageService _DirectMessageService = new DirectMessageService();
            var connectionIds = _DirectMessageService.GetUserConnectionIds(userIds);

            foreach (var connections in connectionIds)
            {
                foreach (var userConnections in connections)
                {
                    await Clients.Client(userConnections.connection_id).SendAsync(message, userId);
                }
            }
        }
Beispiel #5
0
        public ActionResult SendText(SendTextViewModel vm)
        {
            if (ModelState.IsValid)
            {
                String           msg        = String.Format("{0} {1} says: {2}", vm.FirstName, vm.LastName, vm.Message);
                string           AccountSid = Config.TwilioSettings.AccountId();
                string           authToken  = Config.TwilioSettings.AuthToken();
                TwilioRestClient twilio     = new TwilioRestClient(AccountSid, authToken);
                var sentMessage             = twilio.SendSmsMessage(Config.TwilioSettings.TwilioPhoneNumber(), "5628419855", msg);

                return(Json(new { status = "success" }));
            }
            //TODO: handle error if necessary
            return(Json(new { status = "error" }));
        }
Beispiel #6
0
        public IHttpActionResult SendMessage([FromBody] SendTextViewModel textInfo)
        {
            var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
            var username          = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

            var user_id = _accountService.GetAccountByUsername(username).GordonID;

            var result = _DirectMessageService.SendMessage(textInfo, user_id.ToString());

            var data = new NotificationDataViewModel();

            data.messageID = textInfo.id;
            data.roomID    = textInfo.room_id;

            var connectionIDs = _DirectMessageService.GetUserConnectionIds(textInfo.users_ids);

            if (result == false || connectionIDs == null)
            {
                return(NotFound());
            }

            foreach (IEnumerable <ConnectionIdViewModel> connections in connectionIDs)
            {
                foreach (ConnectionIdViewModel model in connections)
                {
                    var pushNotification = new PushNotificationViewModel();
                    pushNotification.body  = textInfo.groupText;
                    pushNotification.to    = model.connection_id;
                    pushNotification.data  = data;
                    pushNotification.title = textInfo.groupName;

                    var myJsonObject = Newtonsoft.Json.JsonConvert.SerializeObject(pushNotification);

                    HttpClient httpClient = new HttpClient();

                    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                    var content = new StringContent(myJsonObject.ToString(), Encoding.UTF8, "application/json");
                    var post    = httpClient.PostAsync("https://exp.host/--/api/v2/push/send", content).Result;
                }
            }

            return(Ok(result));
        }
Beispiel #7
0
        public JsonResult SendText(string sendTextViewModel)
        {
            SendTextViewModel viewModel = JsonConvert.DeserializeObject <SendTextViewModel>(sendTextViewModel);

            //TODO replace this with proper user id from ASPNet Identity
            viewModel.UserId    = this.Identity.ToUserID();
            viewModel.AccountID = this.Identity.ToAccountID();
            SendTextRequest request = new SendTextRequest()
            {
                SendTextViewModel = viewModel
            };
            SendTextResponse response = communicationService.SendText(request);

            if (response.SMSStatus == "Success")
            {
                return(Json(new { success = true, response = "[|Sent successfully|]" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                throw new UnsupportedOperationException(response.Message);
            }
        }
        //create group using user information taken from the front end.
        public CreateGroupViewModel CreateGroup(String name, bool group, string image, List <String> usernames, SendTextViewModel initialMessage, string userId)
        {
            var nameParam       = new SqlParameter("@name", name);
            var groupParam      = new SqlParameter("@group", group);
            var groupImageParam = new SqlParameter("@roomImage", System.Data.SqlDbType.VarBinary, -1);

            groupImageParam.Value = DBNull.Value;

            if (image != null)
            {
                byte[] decodedByteArray = Convert.FromBase64CharArray(image.ToCharArray(), 0, image.Length);
                groupImageParam.Value = decodedByteArray;
            }



            var result = RawSqlQuery <ReturnGroupViewModel> .query("CREATE_MESSAGE_ROOM @name, @group, @roomImage", nameParam, groupParam, groupImageParam); //run stored procedure

            if (result == null)
            {
                throw new ResourceNotFoundException()
                      {
                          ExceptionMessage = "The data was not found."
                      };
            }
            List <string> idlist = new List <String>(500);

            foreach (string username in usernames)
            {
                idlist.Add(_accountService.GetAccountByUsername(username).GordonID);
            }

            var groupObject = new CreateGroupViewModel();

            foreach (ReturnGroupViewModel model in result)
            {
                groupObject.id          = model.id;
                groupObject.name        = model.name;
                groupObject.group       = model.group;
                groupObject.message     = model.message;
                groupObject.group       = model.group;
                groupObject.createdAt   = model.createdAt;
                groupObject.lastUpdated = model.lastUpdated;


                string encodedByteArray = null;

                if (model.image != null)
                {
                    encodedByteArray = Convert.ToBase64String(model.image);
                }

                groupObject.image = encodedByteArray;
            }

            foreach (string userid in idlist)
            {
                var studentIdParam  = new SqlParameter("@user_id", userid);
                var IdRefreshParam2 = new SqlParameter("@_id", groupObject.id);
                var storeRoooms     = RawSqlQuery <MessageViewModel> .query("INSERT_USER_ROOMS @user_id, @_id", studentIdParam, IdRefreshParam2);

                UserViewModel userInfo = new UserViewModel();
                userInfo.user_id   = userid;
                userInfo.user_name = _accountService.Get(userid).ADUserName;
                groupObject.users.Add(userInfo);
            }

            return(groupObject);
        }