コード例 #1
0
        public ActionResult UpdateOrRegister(string username, string password, string passwordrepeat, string address)
        {
            SessionInfoViewModel sivm = new SessionInfoViewModel();

            if (password != passwordrepeat)
            {
                sivm.message = "Passwords don't match ";
            }
            else if (service.GetUsers().Where(x => x.Username == username).FirstOrDefault() != default(Users))
            {
                sivm.message = "Username already taken ";
            }
            else
            {
                Users u = new Users
                {
                    Address  = address,
                    IsAdmin  = -1,
                    Name     = username,
                    Password = password,
                    Username = username
                };
                bool   error = false;
                int    newid = -1;
                string id    = _httpContextAccessor.HttpContext.Request.Cookies["userCookie"];
                if (id == null || id == "")
                {
                    newid = service.AddUser(u);

                    CookieOptions session = new CookieOptions
                    {
                        Expires = DateTime.Now.AddDays(1)
                    };

                    _httpContextAccessor.HttpContext.Response.Cookies.Append("userCookie", newid.ToString(), session);

                    sivm.message = "Account created successfully ! Welcome " + username;
                    error        = true;
                }
                else
                {
                    u.Id         = int.Parse(id);
                    error        = service.UpdateInfoUser(u);
                    sivm.message = "Account updated successfully ";
                    error        = true;
                }


                if (!error)
                {
                    sivm.message = "Oops, couldn't retrieve your account, pleanse try again later !";
                }
            }
            return(View("UserInfo", sivm));
        }
コード例 #2
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (this.NavigationContext.QueryString.ContainsKey("SessionCode"))
            {
                String sessioCode = this.NavigationContext.QueryString["SessionCode"];
                this.viewModel   = new SessionInfoViewModel(this, Int32.Parse(sessioCode));
                this.DataContext = this.viewModel;
            }

            base.OnNavigatedTo(e);
        }
コード例 #3
0
 public override void OnBackPressed()
 {
     AlertDialog.Builder alert = new AlertDialog.Builder(this);
     alert.SetTitle("Please confirm whether to close the application or not.");
     alert.SetPositiveButton("Yes", async(senderAlert, args) =>
     {
         await SessionInfoViewModel.GetLogoutInfo();
         if (SessionInfoViewModel.result == 1)
         {
             LocalStorage.SaveSet("login_session_id", null);
             Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
         }
         else
         {
             var linearLayout           = FindViewById <LinearLayout>(Resource.Id.session_info_view);
             Snackbar snackbar          = Snackbar.Make(linearLayout, "Log out error!", Snackbar.LengthLong);
             Android.Views.View objView = snackbar.View;
             TextView txtAction         = objView.FindViewById <TextView>(Resource.Id.snackbar_action);
             txtAction.SetTextSize(Android.Util.ComplexUnitType.Dip, 18);
             txtAction.SetTextColor(Android.Graphics.Color.White);
             objView.SetBackgroundColor(Color.Red);
             //set message text color
             TextView txtMessage = objView.FindViewById <TextView>(Resource.Id.snackbar_text);
             txtMessage.SetTextColor(Android.Graphics.Color.White);
             txtMessage.SetTextSize(Android.Util.ComplexUnitType.Dip, 18);
             snackbar.Show();
         }
     });
     alert.SetNegativeButton("No", (senderAlert, args) =>
     {
     });
     RunOnUiThread(() =>
     {
         alert.Show();
     });
 }