Esempio n. 1
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();
                    }
                }
            }
        }
Esempio n. 2
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";
                }
            }
        }
Esempio n. 3
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";
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 5
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);
                }
            }
        }
Esempio n. 6
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";
            }
        }
Esempio n. 7
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 void AddEditCategory(object sender, DataGridCellEditEndingEventArgs e)
        {
            TextBox textBox    = e.EditingElement as TextBox;
            var     currentRow = e.Row.DataContext as Category;

            if (!CategoryCreationMode)
            {
                if (String.IsNullOrWhiteSpace(textBox.Text))
                {
                    e.Cancel = true;
                }
                else
                {
                    var editedrow = Context.Categories.Where(a => a.id == currentRow.id).SingleOrDefault();
                    editedrow.name = textBox.Text;
                    Context.SaveChanges();
                }
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(textBox.Text))
                {
                    var rowIndex = e.Row.GetIndex();
                    if (rowIndex == Categories.Count - 1)
                    {
                        Context.Categories.Add(new Category()
                        {
                            name = textBox.Text, companies_id = Company.id, users_id = User.id
                        });
                        Context.SaveChanges();
                    }
                    else
                    {
                        var editedrow = Context.Categories.Where(a => a.id == currentRow.id).SingleOrDefault();
                        editedrow.name = textBox.Text;
                        Context.SaveChanges();
                    }
                    Categories = LoadAllCategoriesofCompany;
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }
        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();
                }
            }
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
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 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");
                }
            }
        }