Exemplo n.º 1
0
        private bool EditAccount(AccountVM acc, bool edit)
        {
            if (acc == null)
            {
                return(false);
            }

            string myUrl = edit ? url + "mod" : url + "add";
            Dictionary <string, string> postData = new Dictionary <string, string>();

            if (edit)
            {
                postData.Add(nameof(AccountVM.AccountId), acc.AccountId.ToString());
            }
            postData.Add(nameof(AccountVM.Name), acc.Name);
            postData.Add(nameof(AccountVM.Email), acc.Email);
            postData.Add(nameof(AccountVM.Address), acc.Address);
            postData.Add(nameof(AccountVM.BirthDate), acc.BirthDate.ToString());
            postData.Add(nameof(AccountVM.Minute), acc.Minute.ToString());
            postData.Add(nameof(AccountVM.Monthly), acc.Monthly.ToString());

            string  json = client.PostAsync(myUrl, new FormUrlEncodedContent(postData)).Result.Content.ReadAsStringAsync().Result;
            JObject obj  = JObject.Parse(json);

            return((bool)obj["OperationResult"]);
        }
Exemplo n.º 2
0
        public void DeleteAccount(AccountVM acc)
        {
            bool success = false;

            if (acc != null)
            {
                string  json = client.GetStringAsync(url + "del/" + acc.AccountId).Result;
                JObject obj  = JObject.Parse(json);
                success = (bool)obj["OperationResult"];
            }
            SendMessage(success);
        }
Exemplo n.º 3
0
 public void CopyFrom(AccountVM other)
 {
     if (other == null)
     {
         return;
     }
     this.AccountId = other.AccountId;
     this.Name      = other.Name;
     this.Email     = other.Email;
     this.Address   = other.Address;
     this.BirthDate = other.BirthDate;
     this.Minute    = other.Minute;
     this.Monthly   = other.Monthly;
 }
Exemplo n.º 4
0
        public void EditAccount(AccountVM acc, Func <AccountVM, bool> editor)
        {
            AccountVM clone = new AccountVM();

            if (acc != null)
            {
                clone.CopyFrom(acc);
            }
            bool?success = editor?.Invoke(clone);

            if (success == true)
            {
                if (acc != null)
                {
                    success = this.EditAccount(clone, true);
                }
                else
                {
                    success = this.EditAccount(clone, false);
                }
                SendMessage(success == true);
            }
        }