Example #1
0
        private IHttpActionResult ValidateUserCanBeDeleted(string authToken)
        {
            IdentityWSSoapClient ws       = new IdentityWSSoapClient();
            IdentityData         identity = ws.GetIdentity(new IdentityWS.Security {
                BinarySecurityToken = authToken
            });
            DataAccessSoapClient dataWS = new DataAccessSoapClient();

            OrderData[] orders = dataWS.FindOrdersByUsername(new DataAccessWS.Security {
                BinarySecurityToken = authToken
            }, identity.Username);
            if (orders != null && orders.Length > 0)
            {
                return(BadRequest("User cannot be removed since he/she has registered orders"));
            }
            return(null);
        }
        private async Task <bool> listOrders(Message message)
        {
            string[] parts = message.Text.Split(new char[0]);
            if (parts.Length != 2)
            {
                await BotClient.SendTextMessageAsync(message.Chat.Id, "Listorders command format: /listorders authToken");

                return(false);
            }
            else
            {
                string authToken              = parts[1];
                IdentityWSSoapClient iWS      = new IdentityWSSoapClient();
                IdentityData         identity = null;
                try
                {
                    identity = iWS.GetIdentity(new identityWS.Security {
                        BinarySecurityToken = authToken
                    });
                }
                catch (Exception ex)
                {
                    await BotClient.SendTextMessageAsync(message.Chat.Id, "An error occurred " + ex.Message);

                    return(false);
                }
                if (identity != null)
                {
                    DataAccessSoapClient ws     = new DataAccessSoapClient();
                    OrderData[]          orders = ws.FindOrdersByUsername(new DataAccessWS.Security {
                        BinarySecurityToken = authToken
                    }, identity.Username);
                    string response = "";
                    foreach (var o in orders)
                    {
                        response += "{" + o.OrderNumber + "} " + o.DateCreated.ToShortDateString() +
                                    " [" + o.State.ToString() + "]\n";
                    }
                    await BotClient.SendTextMessageAsync(message.Chat.Id, response);

                    return(true);
                }
                return(false);
            }
        }