Пример #1
0
        public async Task <IHttpActionResult> SavePortalPerson(int messagePortalPersonId)
        {
            try
            {
                string           url          = this.PortalDBContext.GetMessageGatewaysSync().FirstOrDefault().GatewayURL;
                PortalReturnInfo portalPerson = PortalDBContext.GetPortalByIdSync(messagePortalPersonId);

                bool smsResult = await RestAPIHelper.CallAPI(url, portalPerson.Mobile, portalPerson.MessageText);

                PortalPersonInfo personInfo = new PortalPersonInfo
                {
                    PersonId             = portalPerson.PersonId,
                    MessagePortalGroupId = portalPerson.MessagePortalGroupId,
                    Username             = username
                };
                personInfo.IsSent = smsResult;
                var result = await this.PortalDBContext.UpdatePortalPerson(personInfo);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //return InternalServerError();
        }
Пример #2
0
        public async Task <IHttpActionResult> SavePortalGroup([FromBody] PortalGroupInfo portal)
        {
            try
            {
                portal.Username = username;
                var result = await this.PortalDBContext.SavePortalGroup(portal);

                if (result.IsDbSuccess)
                {
                    int messagePortalGroupId = result.ReturnId;

                    string url = this.PortalDBContext.GetMessageGatewayByIdSync(portal.MessageGatewayId).GatewayURL;

                    foreach (var p in portal.Persons)
                    {
                        string mobile = this.PersonDBContext.GetPersonByIdSync(p).Mobile;

                        bool smsResult = await RestAPIHelper.CallAPI(url, mobile, portal.MessageText);

                        PortalPersonInfo personInfo = new PortalPersonInfo
                        {
                            PersonId             = p,
                            MessagePortalGroupId = messagePortalGroupId,
                            Username             = username
                        };
                        personInfo.IsSent = smsResult;
                        await this.PortalDBContext.UpdatePortalPerson(personInfo);

                        await Task.Delay(2000);
                    }
                }
                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //return InternalServerError();
        }
Пример #3
0
        public async Task <IHttpActionResult> SendMessage(string url, string phone, string message)
        {
            var result = await RestAPIHelper.CallAPI(url, phone, message);

            return(Ok(result));
        }