Example #1
0
        async Task SignIn()
        {
            try
            {
                IsBusy  = true;
                Message = "登录中...(Signing In...)";

                if (string.IsNullOrEmpty(currUser.username) || string.IsNullOrEmpty(currUser.password))
                {
                    Message = "请输入用户名/口令(Please input username/password)";
                }
                else
                {
                    App.ResetCookie();
                    var cookie = await TheLoginDataStore.DoLogin(currUser.username, currUser.password);

                    if (cookie != null)
                    {
                        Settings.Cookie = cookie.cookie_name + "=" + cookie.cookie;
                        Settings.UserId = cookie.user.id;
                        MyHttpClient.Instance.SetCookie();
                        App.GoToMainPage();
                    }
                }
            }
            catch (Exception ex)
            {
                Message = ErrorMessage.GetMessage(ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #2
0
        public async Task <bool> Save()
        {
            if (IsBusy)
            {
                return(false);
            }

            IsBusy  = true;
            Message = string.Empty;
            if (String.IsNullOrEmpty(Item.title))
            {
                Message += "请输入标题(please input title)";
            }
            if (String.IsNullOrEmpty(Item.content))
            {
                Message += "\r\n请输入内容(please input content)";
            }
            if (_bufferPath.Count == 0)
            {
                Message += "\r\n请上传图片(please upload pictures)";
            }
            if (String.IsNullOrEmpty(Item.address))
            {
                Message += "\r\n请输入地址(please input address)";
            }

            if (!string.IsNullOrEmpty(Message))
            {
                IsBusy = false;
                return(false);
            }

            try
            {
                Message = "正在连接服务器(connecting)...";
                string id = await ThePropertyDataStore.AddItemAsync(Item);

                int i = 0;
                Item.attachments = new List <Attachment>();
                foreach (string str in _bufferPath)
                {
                    if (str == string.Empty)
                    {
                        break;
                    }
                    Message = String.Format("上传第{0}张图片(uploading image {0})", i + 1);
                    await TheMediaDataStore.UploadImage(str, id, i.ToString());

                    i++;
                }
                if (Item.address != App.CurrentUser.address)
                {
                    App.CurrentUser.address = Item.address.Trim();
                    await TheLoginDataStore.SaveCurrentUser(App.CurrentUser);
                }
                Item = await ThePropertyDataStore.GetItem(id);

                return(true);
            }
            catch (System.Exception ex)
            {
                Message = ErrorMessage.GetMessage(ex.Message);
                IsBusy  = false;
                return(false);
            }
            finally
            {
                IsBusy  = false;
                Message = string.Empty;
            }
        }
Example #3
0
 public async Task SaveCurrentUserInfo()
 {
     await TheLoginDataStore.SaveCurrentUser(CurrentUser);
 }
Example #4
0
 public async Task Register()
 {
     App.ResetCookie();
     await TheLoginDataStore.RegisterUser(currUser);
 }