Exemple #1
0
        public void CreateUser()
        {
            if (String.IsNullOrWhiteSpace(ErrorUserName) && String.IsNullOrWhiteSpace(ErrorUserEmail) &&
                String.IsNullOrWhiteSpace(ErrorPassword) && String.IsNullOrWhiteSpace(ErrorConfirmPassword) && String.IsNullOrWhiteSpace(ErrorUserRole))
            {
                using (var ctx = new Choukash_Revamp_DemoEntities())
                {
                    ctx.Users.Add(new User()
                    {
                        name         = UserName,
                        email        = UserEmail,
                        password     = Password,
                        companies_id = UserCompany.id,
                        roles_id     = CurrentUserRole.id
                    });

                    ctx.SaveChanges();
                    LoadAllUsersFromCompany(UserCompany);
                    ReloadAllUserInfo();
                }
            }
            else if (CurrentUserRole == null)
            {
                ErrorUserRole = "Please select a role";
            }
        }
Exemple #2
0
 private void Email_LostFocus(object sender, RoutedEventArgs e)
 {
     if (String.IsNullOrWhiteSpace(this.Email.Text))
     {
         this.ErrorEmail.Text = "Please Enter an Email Id.";
     }
     else
     {
         if (!ValidationClass.ValidateEmailID(this.Email.Text))
         {
             this.ErrorEmail.Text = "This is not a valid Email Id.";
         }
         else
         {
             using (var ctx = new Choukash_Revamp_DemoEntities()) {
                 var email = ctx.SuperAdmins.Where(a => a.email == this.Email.Text).FirstOrDefault <SuperAdmin>();
                 if (email == null)
                 {
                     this.ErrorEmail.Text = "";
                 }
                 else
                 {
                     this.ErrorEmail.Text = "This email is alraedy associated with another user";
                 }
             }
         }
     }
 }
Exemple #3
0
        private void CreateRoleforCompany()
        {
            if (String.IsNullOrWhiteSpace(ErrorRoleName) && String.IsNullOrWhiteSpace(ErrorRoleDescription))
            {
                if (this.CheckAllPermissions())
                {
                    using (var ctx = new Choukash_Revamp_DemoEntities())
                    {
                        IList <Permission> permissions = new List <Permission>();
                        Role user_role = new Role()
                        {
                            name         = RoleName,
                            description  = RoleDescription,
                            companies_id = UserCompany.id
                        };
                        for (int i = 0; i < ListPermissions.Count(); i++)
                        {
                            if (ListPermissions[i].IsChecked)
                            {
                                permissions.Add(AllPermissions[i]);
                            }
                        }
                        if (this.NextPage == null && this.Title == "Create Role")
                        {
                            UserPage      = new CreateUserViewModel("Create Admin", this.UserCompany, user_role, permissions, this.EventAggregator);
                            this.NextPage = new NavigatePage(UserPage);
                            this.EventAggregator.PublishOnUIThread(NextPage);
                        }
                        else if (this.NextPage == null && this.Title == "Add Role")
                        {
                            ctx.Roles.Add(user_role);
                            CastPermissiontoRolePermission(user_role, permissions, ctx);
                            ctx.SaveChanges();

                            var sa = ctx.SuperAdmins.Where(a => a.id == UserCompany.superadmin_id).SingleOrDefault <SuperAdmin>();
                            this.EventAggregator.PublishOnUIThread("Operation complete");
                            EditPage      = new EditProductViewModel(sa, EventAggregator);
                            this.NextPage = new NavigatePage(EditPage);
                            this.EventAggregator.PublishOnUIThread(NextPage);
                        }
                        else if (this.NextPage == null && this.Title == "Add new Role")
                        {
                            ctx.Roles.Add(user_role);
                            CastPermissiontoRolePermission(user_role, permissions, ctx);
                            ctx.SaveChanges();
                            this.EventAggregator.PublishOnUIThread("Added new Role");
                            this.EventAggregator.PublishOnUIThread(this);
                        }
                        else
                        {
                            this.EventAggregator.PublishOnUIThread(NextPage);
                        }
                    }
                }
                else
                {
                    ErrorSelectionPermission = "Please Provide Permission for Role";
                }
            }
        }
Exemple #4
0
        private void EditUser()
        {
            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                var user  = ctx.Users.Include(a => a.Role).Include(a => a.Company).Where(a => a.id == CurrentUser.id).SingleOrDefault <User>();
                var _user = this.UserCollection.Where(a => a.id == CurrentUser.id).SingleOrDefault <User>();
                if (user.name != UserName)
                {
                    user.name  = UserName;
                    _user.name = UserName;
                }
                else if (user.email != UserEmail)
                {
                    user.email  = UserEmail;
                    _user.email = UserEmail;
                }
                else if (user.password != Password)
                {
                    user.password  = Password;
                    _user.password = Password;
                }
                else if (user.roles_id != CurrentUserRole.id)
                {
                    user.Role  = CurrentUserRole;
                    _user.Role = CurrentUserRole;
                }

                ctx.SaveChanges();
                ReloadUserCollection(user.Company);
            }
        }
Exemple #5
0
        public void LoadUserDetails(User user)
        {
            if (user != null && SelectedUser != null)
            {
                ReloadAllUserInfo();
                CurrentUser         = user;
                ShowDetail          = true;
                EditUserMode        = true;
                AllowCreationOfUser = false;
                BorderThickness     = 0;


                using (var ctx = new Choukash_Revamp_DemoEntities())
                {
                    if (this.UserRoles != null)
                    {
                        this.UserRoles.Clear();
                    }
                    var compnay_roles = ctx.Companies.Include(a => a.Roles).Where(a => a.id == user.companies_id).SingleOrDefault <Company>();


                    this.UserRoles = new ObservableCollection <Role>(compnay_roles.Roles);

                    UserName        = user.name;
                    UserEmail       = user.email;
                    Password        = user.password;
                    ConfirmPassword = user.password;
                    CurrentUserRole = compnay_roles.Roles.Where(a => a.id == user.roles_id).SingleOrDefault <Role>();
                }
            }
        }
Exemple #6
0
        public void DeleteCompany(Company currentCompany)
        {
            if (currentCompany != null)
            {
                using (var ctx = new Choukash_Revamp_DemoEntities())
                {
                    var company = ctx.Companies.Where(a => a.id == currentCompany.id).SingleOrDefault <Company>();
                    if (company != null)
                    {
                        var company_users = ctx.Users.Where(a => a.companies_id == company.id).ToList <User>();
                        var company_roles = ctx.Roles.Where(a => a.companies_id == company.id).ToList <Role>();


                        if (company_users.Count > 0 || company_roles.Count > 0)
                        {
                            ctx.Users.RemoveRange(company_users);
                            //ctx.SaveChanges();

                            foreach (var role in company_roles)
                            {
                                var role_permissions = ctx.Role_Permission.Where(a => a.roles_id == role.id).ToList <Role_Permission>();
                                ctx.Role_Permission.RemoveRange(role_permissions);
                            }

                            ctx.Roles.RemoveRange(company_roles);
                            ctx.SaveChanges();
                        }
                        ctx.Companies.Remove(company);
                        ctx.SaveChanges();
                        this.CompanyCollection.Clear();
                        GetAllCompanies();
                    }
                }
            }
        }
Exemple #7
0
 private void GetAllCompanies()
 {
     using (var ctx = new Choukash_Revamp_DemoEntities())
     {
         var companies = ctx.Companies.Include(a => a.Roles).Include(a => a.Users).ToList();
         this.CompanyCollection = new ObservableCollection <Company>(companies);
     }
 }
Exemple #8
0
        private void EditRole()
        {
            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                var role = ctx.Roles.Include(a => a.Role_Permission).Where(a => a.id == UserRole.id).SingleOrDefault <Role>();
                role.name        = RoleName;
                role.description = RoleDescription;

                IList <Permission> permissions = new List <Permission>();
                for (int i = 0; i < ListPermissions.Count(); i++)
                {
                    if (ListPermissions[i].IsChecked)
                    {
                        permissions.Add(AllPermissions[i]);
                    }
                }

                foreach (var permission in permissions)
                {
                    if (!role.Role_Permission.Contains(ctx.Role_Permission.Where
                                                           (a => a.permissions_id == permission.id && a.roles_id == UserRole.id).SingleOrDefault <Role_Permission>()))
                    {
                        ctx.Role_Permission.Add(new Role_Permission()
                        {
                            roles_id       = UserRole.id,
                            permissions_id = permission.id
                        });
                    }
                }

                foreach (var rp in role.Role_Permission.ToList())
                {
                    if (!permissions.Contains(AllPermissions.Where(a => a.id == rp.permissions_id).SingleOrDefault <Permission>()))
                    {
                        ctx.Role_Permission.Remove(rp);
                    }
                }
                ctx.SaveChanges();



                if (this.Title == "Edit Role")
                {
                    this.EventAggregator.PublishOnUIThread("Operation complete");

                    var editpage = new EditProductViewModel(ctx.SuperAdmins.Where(a => a.id == UserCompany.superadmin_id).SingleOrDefault <SuperAdmin>(), this.EventAggregator);
                    var tool     = new NavigatePage(editpage);
                    this.EventAggregator.PublishOnUIThread(tool);
                }
                else if (this.Title == "Edit Existing Role")
                {
                    this.EventAggregator.PublishOnUIThread("Edited Existing Role");
                    this.EventAggregator.PublishOnUIThread(this);
                }
            }
        }
Exemple #9
0
 private void GetAllPermissions()
 {
     using (var ctx = new Choukash_Revamp_DemoEntities())
     {
         foreach (var p in ctx.Permissions)
         {
             AllPermissions.Add(p);
             ListPermissions.Add(new CheckBoxListViewItem(p.menu, false));
         }
     }
 }
Exemple #10
0
 private void ConfigureforUser()
 {
     using (var ctx = new Choukash_Revamp_DemoEntities())
     {
         var company = ctx.Companies.Include(a => a.Roles).Include(a => a.Users).Where(a => a.id == User.companies_id).SingleOrDefault();
         this.CompanyCollection = new ObservableCollection <Company>()
         {
             company
         };
         LoadAllUsersFromCompany(company);
         this.SelectedCompany = CompanyCollection.FirstOrDefault();
     }
 }
Exemple #11
0
        public static bool UniqueTestforEmail(string email, string model)
        {
            bool doesExist = true;

            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                switch (model)
                {
                case "User":
                    var user = ctx.Users.Where(a => a.email == email).SingleOrDefault <User>();
                    if (user != null)
                    {
                        doesExist = false;
                    }
                    else
                    {
                        doesExist = true;
                    }
                    break;

                case "SuperAdmin":
                    var sa = ctx.SuperAdmins.Where(a => a.email == email).SingleOrDefault <SuperAdmin>();
                    if (sa != null)
                    {
                        doesExist = false;
                    }
                    else
                    {
                        doesExist = true;
                    }
                    break;

                case "Company":
                    var company = ctx.Companies.Where(a => a.email == email).SingleOrDefault <Company>();
                    if (company != null)
                    {
                        doesExist = false;
                    }
                    else
                    {
                        doesExist = true;
                    }
                    break;

                default:
                    break;
                }
            }
            return(doesExist);
        }
Exemple #12
0
        public void UpdateRole(Role role, User user)
        {
            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                var _user = ctx.Users.Include(a => a.Role).Where(a => a.id == SelectedUser.id).SingleOrDefault <User>();
                _user.roles_id = role.id;

                ctx.SaveChanges();


                this.UserCollection = new ObservableCollection <User>(ctx.Users.Include(a => a.Role).Include(a => a.Company).
                                                                      Where(a => a.companies_id == SelectedUser.companies_id).ToList <User>());
                ErrorUserRole = "Successfully updated role";
            }
        }
Exemple #13
0
 public void DeleteUser(User user)
 {
     using (var ctx = new Choukash_Revamp_DemoEntities())
     {
         if (user != null)
         {
             var _user        = ctx.Users.Include(a => a.Role).Include(a => a.Company).Where(a => a.id == user.id).FirstOrDefault <User>();
             var _userCompany = ctx.Companies.Include(a => a.Roles).Where(a => a.id == _user.companies_id).FirstOrDefault <Company>();
             ctx.Users.Remove(_user);
             ctx.SaveChanges();
             LoadAllUsersFromCompany(_userCompany);
             LoadUserDetails(this.UserCollection.FirstOrDefault());
         }
     }
 }
        public ShellViewModel()
        {
            this.WindowHeight = 500;
            this.WindowWidth  = 600;

            using (var ctx = new Choukash_Revamp_DemoEntities()) {
                int __count = ctx.SuperAdmins.Count <SuperAdmin>();
                if (__count == 0)
                {
                    ActivateItem(new SuperAdminCreateViewModel());
                }
                else
                {
                    ActivateItem(new UserLoginViewModel());
                }
            }
        }
        public SuperAdminMainViewModel(SuperAdmin sa)
        {
            this.WelcomeMessage = "Welcome " + sa.name;

            this.EventAggregator = new EventAggregator();
            this.EventAggregator.Subscribe(this);

            this.SA = sa;

            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                if (ctx.Permissions.Count <Permission>() == 0)
                {
                    IList <Permission> permission = new List <Permission>()
                    {
                        new Permission()
                        {
                            menu = "Category Create"
                        },
                        new Permission()
                        {
                            menu = "Categroy Delete"
                        },
                        new Permission()
                        {
                            menu = "Subcategory Create"
                        },
                        new Permission()
                        {
                            menu = "Subcategory Delete"
                        },
                        new Permission()
                        {
                            menu = "Item Create"
                        },
                        new Permission()
                        {
                            menu = "Item Delete"
                        }
                    };

                    ctx.Permissions.AddRange(permission);
                    ctx.SaveChanges();
                }
            }
        }
Exemple #16
0
 private void ConfigurePermissionAccordingtoRole()
 {
     using (var ctx = new Choukash_Revamp_DemoEntities())
     {
         var role_permissions = ctx.Role_Permission.Include(a => a.Role).Include(a => a.Permission).Where(a => a.roles_id == UserRole.id).ToList <Role_Permission>();
         foreach (var role_permission in role_permissions)
         {
             var permission = role_permission.Permission;
             foreach (var item in ListPermissions)
             {
                 if (permission.menu == item.Text)
                 {
                     item.IsChecked = true;
                     break;
                 }
             }
         }
     }
 }
Exemple #17
0
        private void EditCompanyOnly()
        {
            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                var company = ctx.Companies.Where(a => a.id == _company.id).SingleOrDefault <Company>();

                company.name        = Name;
                company.email       = Email;
                company.location    = Location;
                company.description = Description;

                ctx.SaveChanges();

                this.EventAggregator.PublishOnUIThread("Operation complete");

                var editpage = new EditProductViewModel(this.SA, this.EventAggregator);
                var tool     = new NavigatePage(editpage);
                this.EventAggregator.PublishOnUIThread(tool);
            }
        }
Exemple #18
0
        private void CreateCompanyOnly()
        {
            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                ctx.Companies.Add(new Company()
                {
                    name          = Name,
                    email         = Email,
                    location      = Location,
                    description   = Description,
                    superadmin_id = this.SA.id
                });
                ctx.SaveChanges();

                this.EventAggregator.PublishOnUIThread("Operation complete");

                var editpage = new EditProductViewModel(this.SA, this.EventAggregator);
                var tool     = new NavigatePage(editpage);
                this.EventAggregator.PublishOnUIThread(tool);
            }
        }
        public void Login()
        {
            if (!String.IsNullOrWhiteSpace(UserName) && !String.IsNullOrWhiteSpace(Password))
            {
                using (var ctx = new Choukash_Revamp_DemoEntities())
                {
                    var sa   = ctx.SuperAdmins.Where(a => (a.name == UserName) && (a.password == Password)).FirstOrDefault <SuperAdmin>();
                    var user = ctx.Users.Include(a => a.Company).Include(a => a.Role).Where(a => (a.name == UserName) && (a.password == Password)).FirstOrDefault <User>();

                    if (sa == null && user == null)
                    {
                        ErrorUserName = "******";
                    }
                    else if (sa == null && user != null)
                    {
                        DeactivateItem(this, true);
                        base.TryClose();
                        Navigator.Navigator.Navigate <ShellViewModel>(user);

                        Application.Current.Windows[0].Close();
                    }
                    else if (sa != null && user == null)
                    {
                        DeactivateItem(this, true);
                        base.TryClose();
                        Navigator.Navigator.Navigate <ShellViewModel>(sa);

                        Application.Current.Windows[0].Close();
                    }
                }
            }
            else if (String.IsNullOrWhiteSpace(UserName))
            {
                ErrorUserName = "******";
            }
            else
            {
                ErrorPassword = "******";
            }
        }
Exemple #20
0
        public void LoadAllUsersFromCompany(Company usercompany)
        {
            if (usercompany != null)
            {
                ShowDetail       = false;
                this.UserCompany = usercompany;
                ReloadAllUserInfo();
                CDUser = true;


                if (BorderThickness == 1)
                {
                    BorderThickness = 0;
                }

                using (var ctx = new Choukash_Revamp_DemoEntities())
                {
                    //if (this.UserCollection != null)
                    //{
                    //    SelectedUser = null;
                    //    this.UserCollection.Clear();
                    //}
                    var users = ctx.Users.Include(a => a.Role).Include(a => a.Company).Where(a => a.companies_id == usercompany.id).ToList();

                    //foreach (var user in users)
                    //{
                    //    user.Role = ctx.Roles.Where(a => a.id == user.roles_id).SingleOrDefault<Role>();
                    //}

                    this.UserCollection = new ObservableCollection <User>(users);

                    this.UserRoles = new ObservableCollection <Role>(usercompany.Roles);
                }
            }
            else
            {
                this.UserCollection = null;
            }
        }
        public void CreateSuperAdmin()
        {
            using (var ctx = new Choukash_Revamp_DemoEntities())
            {
                var sa = new SuperAdmin()
                {
                    name      = Name,
                    email     = Email,
                    password  = Password,
                    is_active = true
                };
                ctx.SuperAdmins.Add(sa);
                ctx.SaveChanges();

                MessageBox.Show("Admin Created Successfully");
            }

            DeactivateItem(this, true);
            base.TryClose();

            Navigator.Navigator.Navigate <ShellViewModel>();
            Application.Current.Windows[0].Close();
        }
        public void ConfigureFullProduct()
        {
            if (String.IsNullOrWhiteSpace(ErrorUserName) && String.IsNullOrWhiteSpace(ErrorUserEmail) &&
                String.IsNullOrWhiteSpace(ErrorPassword) && String.IsNullOrWhiteSpace(ErrorConfirmPassword))
            {
                using (var ctx = new Choukash_Revamp_DemoEntities())
                {
                    ctx.Companies.Add(Company);
                    ctx.Roles.Add(UserRole);

                    foreach (var _permission in UserPermissions)
                    {
                        var rolepermission = new Role_Permission()
                        {
                            roles_id       = UserRole.id,
                            permissions_id = _permission.id
                        };
                        ctx.Role_Permission.Add(rolepermission);
                    }
                    var admin = new User()
                    {
                        name         = UserName,
                        email        = UserEmail,
                        password     = Password,
                        companies_id = Company.id,
                        roles_id     = UserRole.id
                    };
                    ctx.Users.Add(admin);
                    ctx.SaveChanges();

                    MessageBox.Show("New User Created");

                    this.EventAggregator.PublishOnUIThread("Operation complete");
                }
            }
        }
Exemple #23
0
 private void ConfigureInitialRole()
 {
     using (var ctx = new Choukash_Revamp_DemoEntities())
     {
         var company = new Company()
         {
             name          = Name,
             email         = Email,
             location      = Location,
             description   = Description,
             superadmin_id = SA.id
         };
         if (this.NextPage == null)
         {
             RolePage      = new CreateRoleViewModel("Create Role", null, company, this.EventAggregator);
             this.NextPage = new NavigatePage(RolePage);
             this.EventAggregator.PublishOnUIThread(NextPage);
         }
         else
         {
             this.EventAggregator.PublishOnUIThread(NextPage);
         }
     }
 }
        public void Validation(string ControlName)
        {
            switch (ControlName)
            {
            case "UserName":
                if (String.IsNullOrWhiteSpace(UserName))
                {
                    ErrorUserName = "******";
                    break;
                }
                else
                {
                    ErrorUserName = "";
                }
                break;

            case "UserEmail":
                if (String.IsNullOrWhiteSpace(UserEmail))
                {
                    ErrorUserEmail = "Please enter email";
                    break;
                }
                else
                {
                    if (!ValidationClass.ValidateEmailID(UserEmail))
                    {
                        ErrorUserEmail = "This email id is not valid";
                        break;
                    }
                    else
                    {
                        using (var ctx = new Choukash_Revamp_DemoEntities())
                        {
                            var email = ctx.Users.Where(a => a.email == this.UserEmail).FirstOrDefault <User>();
                            if (email == null)
                            {
                                this.ErrorUserEmail = "";
                            }
                            else
                            {
                                this.ErrorUserEmail = "This email is alraedy associated with another user";
                            }
                        }
                        break;
                    }
                }

            case "Password":
                if (String.IsNullOrWhiteSpace(Password))
                {
                    ErrorPassword = "******";
                    break;
                }
                else
                {
                    if (!ValidationClass.ValidatePassword(Password))
                    {
                        ErrorPassword = "******";
                        break;
                    }
                    else
                    {
                        ErrorPassword = "";
                        break;
                    }
                }

            case "ConfirmPassword":
                if (String.IsNullOrWhiteSpace(ConfirmPassword))
                {
                    ErrorConfirmPassword = "******";
                    break;
                }
                else
                {
                    if (Password != ConfirmPassword)
                    {
                        ErrorConfirmPassword = "******";
                    }
                    else
                    {
                        ErrorConfirmPassword = "";
                    }

                    break;
                }
            }
        }
Exemple #25
0
 private void CastPermissiontoRolePermission(Role user_role, IList <Permission> permissions, Choukash_Revamp_DemoEntities ctx)
 {
     foreach (var permission in permissions)
     {
         ctx.Role_Permission.Add(new Role_Permission()
         {
             roles_id       = user_role.id,
             permissions_id = permission.id
         });
     }
 }