public async Task<bool> Login(string username, string password) { try { AccountResponse response; var request = Task.Run(() => response = _client.CreateToken(username, password)); response = await request; if (response.Success) { var user = response.User; CurrentUser = new User { LastName = user.LastName, FirstName = user.FirstName, Email = username, Token = response.Token }; return true; } Console.WriteLine("Login failed: {0}", response.Error); } catch (Exception ex) { Console.WriteLine("Login failed for some reason...: {0}", ex.Message); } return false; }
public string GetJson(User user) { ShippingName = string.Format("{0} {1}", user.FirstName, user.LastName); SsoToken = user.Token; Email = user.Email; Address1 = user.Address; Address2 = user.Address2; City = user.City; State = user.State; ZipCode = user.ZipCode; Phone = user.Phone; Country = user.Country; return Newtonsoft.Json.JsonConvert.SerializeObject(this); }
public ShippingDetailsFragment(User user) { this.user = user; }
public ShippingAddressViewController(User user) { this.Title = "Shipping"; //This hides the back button text when you leave this View Controller this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, handler: null); this.user = user; TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None; Cells.Add(new CustomViewCell(FirstNameField = new TextEntryView { PlaceHolder = "First Name", Value = user.FirstName, })); Cells.Add(new CustomViewCell(LastNameField = new TextEntryView { PlaceHolder = "Last Name", Value = user.LastName, })); Cells.Add(new CustomViewCell(PhoneNumberField = new TextEntryView { PlaceHolder = "Phone Number", Value = user.Phone, KeyboardType = UIKeyboardType.NumberPad, })); Cells.Add(new CustomViewCell(AddressField = new TextEntryView { PlaceHolder = "Address", Value = user.Address, AutocapitalizationType = UITextAutocapitalizationType.Words, })); Cells.Add(new CustomViewCell(Address2Field = new TextEntryView { PlaceHolder = "Address", Value = user.Address2, AutocapitalizationType = UITextAutocapitalizationType.Words, })); Cells.Add(new CustomViewCell(CityField = new TextEntryView { PlaceHolder = "City", Value = user.City, AutocapitalizationType = UITextAutocapitalizationType.Words, })); Cells.Add(new CustomViewCell(PostalField = new TextEntryView { PlaceHolder = "Postal Code", Value = user.ZipCode, KeyboardType = UIKeyboardType.NumbersAndPunctuation, })); Cells.Add(new CustomViewCell(CountryField = new AutoCompleteTextEntry { PlaceHolder = "Country", Title = "Select your Country", Value = user.Country, ValueChanged = (v) => GetStates(), PresenterView = this, })); Cells.Add(new CustomViewCell(StateField = new AutoCompleteTextEntry { PlaceHolder = "State", Value = user.State, Title = "Select your state", PresenterView = this, })); GetCountries(); GetStates(); TableView.Source = new ShippingAddressPageSource { Cells = Cells }; TableView.TableFooterView = new UIView(new RectangleF(0, 0, 0, BottomButtonView.Height)); TableView.ReloadData(); View.AddSubview(BottomView = new BottomButtonView() { ButtonText = "Place Order", ButtonTapped = PlaceOrder, }); }
public Task<OrderResult> PlaceOrder(User user, bool verify = false) { return Task.Factory.StartNew(() => { try { var content = Encoding.UTF8.GetBytes(CurrentOrder.GetJson(user)); var request = CreateRequest("order" + (verify ? "?verify=1" : "")); request.Method = "POST"; request.ContentLength = content.Length; using (Stream s = request.GetRequestStream()) { s.Write(content, 0, content.Length); } string response = ReadResponseText(request); var result = Newtonsoft.Json.JsonConvert.DeserializeObject<OrderResult>(response); if (!verify && result.Success) CurrentOrder = new Order(); return result; } catch (Exception ex) { return new OrderResult { Success = false, Message = ex.Message, }; } }); }
public ProcessingViewController(User user) { Title = "Processing"; this.user = user; this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (sender, args) => this.DismissViewControllerAsync(true)); }