Пример #1
0
 //Instead of SettingsChanged, hook up the separate functions into actions
 private async void SettingsChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName.Equals("Password"))
     {
         var Message = new NewPasswordMessage()
         {
             ApplicationId = _onlineSettings.ApplicationId,
             GroupId       = _onlineSettings.GroupId,
             Password      = _onlineSettings.OldPassword,
             NewPassword   = _onlineSettings.Password
         };
         await Call(Function.ChangePassword, string.Empty, Message);
     }
     else if (e.PropertyName.Equals("GroupId"))
     {
         await Call(Function.Unregister);
         await Call(Function.Register);
     }
 }
Пример #2
0
        //Don't use switch case, it just looks bad in the code and brings in unnecessary noise
        //Split those into 5 small functions instead of using switch
        //You don't have to return NotFound code because you'll get it from server
        public async Task <HttpResponseMessage> Call(Function function, string content = "", NewPasswordMessage pwdChange = null)
        {
            if (function.Equals(Function.Unregister))
            {
                InitNewMessageObject(content, true);
            }
            else
            {
                InitNewMessageObject(content);
            }


            var json          = JsonConvert.SerializeObject(_message);
            var pwdChangeJson = JsonConvert.SerializeObject(pwdChange);

            switch (function)
            {
            case Function.Register:
                return(await Post("http://localhost:7071/api/register", json));

            case Function.Unregister:
                return(await Post("http://localhost:7071/api/unregister", json));

            case Function.UnregisterAll:
                return(await Post("http://localhost:7071/api/unregisterall", json));

            case Function.ChangePassword:
                return(await Post("http://localhost:7071/api/changepassword", pwdChangeJson));

            case Function.SendMessage:
                return(await Post("http://localhost:7071/api/sendmessage", json));

            default:
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
        }