Beispiel #1
0
        public void Navigate(string menu)
        {
            switch (menu)
            {
            case "UsersRoles":
                if (userrolepage == null)
                {
                    userrolepage = new EditProductViewModel(_user, EventAggregator)
                    {
                        DisplayName = "Add User"
                    };
                    ActivateItem(userrolepage);
                }
                else
                {
                    ActivateItem(userrolepage);
                }
                break;

            case "Inventory":
                if (inventorypage == null)
                {
                    inventorypage = new InventoryViewModel(_user, _user.Company, EventAggregator)
                    {
                        DisplayName = "Inventory"
                    };
                    ActivateItem(inventorypage);
                }
                else
                {
                    ActivateItem(inventorypage);
                }
                break;
            }
        }
Beispiel #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";
                }
            }
        }
Beispiel #3
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);
                }
            }
        }
 public void EditExistingProduct()
 {
     if (this.NextPageEdit == null)
     {
         EditPage          = new EditProductViewModel(SA, EventAggregator);
         this.NextPageEdit = new NavigatePage(EditPage);
         this.EventAggregator.PublishOnUIThread(NextPageEdit);
     }
     else
     {
         this.EventAggregator.PublishOnUIThread(NextPageEdit);
     }
 }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
            }
        }