// GET: UserRoll/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserRoll userRoll = db.UserRolls.Find(id);

            if (userRoll == null)
            {
                return(HttpNotFound());
            }
            return(View(userRoll));
        }
        // GET: UserRoll/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserRoll userRoll = db.UserRolls.Find(id);

            if (userRoll == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserID      = new SelectList(db.Users, "Id", "UserName", userRoll.UserID);
            ViewBag.UserGroupID = new SelectList(db.UserGroups, "UserGroupID", "GroupName", userRoll.UserGroupID);
            return(View(userRoll));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            UserRoll userRoll = db.UserRolls.Find(id);

            db.UserRolls.Remove(userRoll);
            int res = db.SaveChanges();

            //return RedirectToAction("Index");
            if (res > 0)
            {
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("error", JsonRequestBehavior.AllowGet));
            }
        }
 public ActionResult Edit([Bind(Include = "UserRollID,UserGroupID,UserID,UserName,IsActive,Status,CreateBy,CreateOn,UpdateBy,UpdateOn,IsDeleted,DeleteBy,DeleteOn")] UserRoll userRoll)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userRoll).State = EntityState.Modified;
         int res = db.SaveChanges();
         //return RedirectToAction("Index");
         if (res > 0)
         {
             return(Json("success", JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json("error", JsonRequestBehavior.AllowGet));
         }
     }
     else
     {
         return(Json("invalid", JsonRequestBehavior.AllowGet));
     }
 }
示例#5
0
        public int MainMany(UserRoll roll)
        {
            List <string> menuItems = new List <string>()
            {
                "Account", "Log Out"
            };

            switch (roll)
            {
            case UserRoll.StandardUser:
                menuItems.Insert(0, "Train");
                menuItems.Insert(0, "Upgrade to Premium");
                break;

            case UserRoll.PremiumUser:
                menuItems.Insert(0, "Train");
                break;

            case UserRoll.TrainerUser:
                menuItems.Insert(0, "Reschedule training");
                break;
            }
            return(ChooseMany(menuItems));
        }
示例#6
0
        async private void btnUserUpdate_Clicked(object sender, EventArgs e)
        {
            var user  = (User)UserDataGrid.SelectedItems[0];
            var Rolls = await SandoghcheController.GetConnection().Table <Roll>().ToListAsync();

            UserRoll userRoll = new UserRoll();

            if (String.IsNullOrWhiteSpace(txtUserFullName.Text))
            {
                await DisplayAlert("خطا", "نام مشترک نمیتواند خالی باشد", "باشه");
            }
            else
            {
                user.FullName = txtUserFullName.Text;
                user.Mobile   = txtUserMobile.Text;
                user.Email    = txtUserEmail.Text;
                user.IsActive = swtUserIsActive.IsToggled;

                if ((chboxAdmin.IsChecked && chboxCashier.IsChecked) || (chboxAdmin.IsChecked && chboxHost.IsChecked) || (chboxCashier.IsChecked && chboxHost.IsChecked))
                {
                    await DisplayAlert("خطا", "تداخل سطوح دسترسی", "باشه");
                }
                else if (chboxAdmin.IsChecked)
                {
                    string query = "delete from UserRolls where UserId=" + user.UserId;
                    await SandoghcheController._connection.QueryAsync <UserRoll>(query);

                    userRoll.RollId = 2;
                    userRoll.UserId = user.UserId;
                    await SandoghcheController._connection.InsertAsync(userRoll);
                }
                else if (chboxCashier.IsChecked)
                {
                    string query = "delete from UserRolls where UserId=" + user.UserId;
                    await SandoghcheController._connection.QueryAsync <UserRoll>(query);

                    userRoll.RollId = 3;
                    userRoll.UserId = user.UserId;
                    await SandoghcheController._connection.InsertAsync(userRoll);
                }
                else if ((chboxHost.IsChecked))
                {
                    string query = "delete from UserRolls where UserId=" + user.UserId;
                    await SandoghcheController._connection.QueryAsync <UserRoll>(query);

                    userRoll.RollId = 4;
                    userRoll.UserId = user.UserId;
                    await SandoghcheController._connection.InsertAsync(userRoll);
                }
                else
                {
                    string query = "delete from UserRolls where UserId=" + user.UserId;
                    await SandoghcheController._connection.QueryAsync <UserRoll>(query);
                }


                await SandoghcheController._connection.UpdateAsync(user);

                txtUserFullName.Text      = "";
                txtUserMobile.Text        = "";
                txtUserEmail.Text         = "";
                swtUserIsActive.IsToggled = true;
                btnUserCancel.IsVisible   = false;
                btnUserDelete.IsVisible   = false;
                btnUserUpdate.IsVisible   = false;
                chboxSuperUser.IsChecked  = false;
                chboxAdmin.IsChecked      = false;
                chboxCashier.IsChecked    = false;
                chboxHost.IsChecked       = false;

                UserDataGrid.ItemsSource = null;

                await GetUsers();
            }
        }
示例#7
0
        private async void btnRegister_Clicked(object sender, EventArgs e)
        {
            User     user     = new User();
            Roll     roll     = new Roll();
            UserRoll userRoll = new UserRoll();

            var users = await SandoghcheController._connection.Table <User>().ToListAsync();


            bool IsValidEmail(string email)
            {
                try
                {
                    var addr = new System.Net.Mail.MailAddress(email);
                    return(addr.Address == email);
                }
                catch
                {
                    return(false);
                }
            }

            if (string.IsNullOrWhiteSpace(txtFullName.Text) ||
                (string.IsNullOrWhiteSpace(txtEmail.Text)) ||
                (string.IsNullOrWhiteSpace(txtMobileNumber.Text)) ||
                (string.IsNullOrWhiteSpace(txtPassword.Text)) ||
                (string.IsNullOrWhiteSpace(txtRepeatPassword.Text)))
            {
                await DisplayAlert("ورود اطلاعات", "اطلاعات ناقص است", "باشه");
            }
            else if (!string.Equals(txtPassword.Text, txtRepeatPassword.Text))
            {
                await DisplayAlert("ورود اطلاعات", "رمز عبور یکسان نیست", "باشه");

                txtPassword.Text       = string.Empty;
                txtRepeatPassword.Text = string.Empty;
            }
            else if (!IsValidEmail(txtEmail.Text))
            {
                await DisplayAlert("ورود اطلاعات", "ایمل نامعتبر", "باشه");
            }
            else
            {
                var hash = new PasswordHash(txtPassword.Text.ToLower());
                user.FullName     = txtFullName.Text;
                user.Email        = txtEmail.Text.ToLower();
                user.Mobile       = txtMobileNumber.Text;
                user.PasswordHash = Convert.ToBase64String(hash.ToArray());
                user.IsActive     = true;

                var CheckIfUserExist = await SandoghcheController._connection.Table <User>().FirstOrDefaultAsync(x => x.Email.ToLower() == txtEmail.Text.ToLower() || x.Mobile == txtMobileNumber.Text);

                var CheckIfUserTableIsEmpty = await SandoghcheController._connection.Table <User>().FirstOrDefaultAsync();

                if (CheckIfUserTableIsEmpty == null)
                {
                    roll.RollName = "مدیر ارشد";
                    await SandoghcheController._connection.InsertAsync(roll);

                    roll.RollName = "مدیر";
                    await SandoghcheController._connection.InsertAsync(roll);

                    roll.RollName = "صندوقدار";
                    await SandoghcheController._connection.InsertAsync(roll);

                    roll.RollName = "میزبان";
                    await SandoghcheController._connection.InsertAsync(roll);

                    roll.RollName = "بازاریاب";
                    await SandoghcheController._connection.InsertAsync(roll);

                    userRoll.RollId = 1;
                    userRoll.UserId = 1;

                    await SandoghcheController._connection.InsertAsync(user);

                    await SandoghcheController._connection.InsertAsync(userRoll);

                    //Application.Current.Properties["Email"] = txtEmail.Text.ToLower();

                    Application.Current.Properties["FullName"] = user.FullName;

                    Application.Current.Properties["userRollName"] = "مدیر ارشد";


                    txtFullName.Text       = string.Empty;
                    txtEmail.Text          = string.Empty;
                    txtMobileNumber.Text   = string.Empty;
                    txtRepeatPassword.Text = string.Empty;
                    txtPassword.Text       = string.Empty;



                    await Application.Current.SavePropertiesAsync();

                    await Navigation.PushAsync(new SandoghcheMainPage());
                }
                else
                {
                    if (CheckIfUserExist != null)
                    {
                        await DisplayAlert("خطا", "این شماره موبایل یا ایمیل  قبلا ثبت شده است ", "باشه");

                        txtEmail.Text        = string.Empty;
                        txtMobileNumber.Text = string.Empty;
                        return;
                    }

                    await SandoghcheController._connection.InsertAsync(user);

                    //Application.Current.Properties["Email"] = txtEmail.Text.ToLower();

                    //Application.Current.Properties["FullName"] = user.FullName;

                    //Application.Current.Properties["userRollName"] = roll.RollName;


                    txtFullName.Text       = string.Empty;
                    txtEmail.Text          = string.Empty;
                    txtMobileNumber.Text   = string.Empty;
                    txtRepeatPassword.Text = string.Empty;
                    txtPassword.Text       = string.Empty;



                    await Application.Current.SavePropertiesAsync();

                    await Navigation.PushAsync(new MainPage());
                }
            }
        }