Exemplo n.º 1
0
        public BrandSectionPermissionViewModel()
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }
            Client.GetAllBrandsAsync(LoggedUserInfo.Iserial);

            Client.GetAllBrandsCompleted += (d, s) =>
            {
                BrandList = s.Result;
            };

            lkpClient.GetTblBrandSectionLinkCompleted += (s, sv) =>
            {
                BrandSectionList.Clear();
                foreach (var row in sv.Result)
                {
                    BrandSectionList.Add(row.TblLkpBrandSection1);
                }
            };

            Client.GetUserSpectialPermissionsAsync();
            Client.GetUserSpectialPermissionsCompleted += (s, sv) =>
            {
                foreach (var row in sv.Result)
                {
                    PermissionList.Add(new TblBrandSectionPermissionViewModel
                    {
                        TblAuthPermission = row.Iserial,
                        Ename             = row.Ename,
                    });
                }
            };

            Client.GetTblBrandSectionPermissionCompleted += (s, sv) =>
            {
                foreach (var oldrow in PermissionList)
                {
                    oldrow.Iserial   = 0;
                    oldrow.Financial = oldrow.Retail = oldrow.Technical = false;
                }

                foreach (var row in sv.Result)
                {
                    var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission && row.BrandCode == SelectedBrand.Brand_Code && row.TblLkpBrandSection == SelectedBrandSection.Iserial
                                                                       );
                    if (permissionRow != null)
                    {
                        permissionRow.InjectFrom(row);
                    }
                }
            };

            Client.UpdateOrInsertTblBrandSectionPermissionCompleted += (s, x) =>
            {
                var savedRow = (TblBrandSectionPermissionViewModel)PermissionList.GetItemAt(x.outindex);

                if (savedRow != null)
                {
                    savedRow.InjectFrom(x.Result);
                }
            };

            Client.DeleteTblBrandSectionPermissionCompleted += (s, ev) =>
            {
                var oldrow = PermissionList.FirstOrDefault(x => x.Iserial == ev.Result);
                if (oldrow != null)
                {
                    oldrow.Iserial   = 0;
                    oldrow.Financial = oldrow.Retail = oldrow.Technical = false;
                }
            };
        }
Exemplo n.º 2
0
        public UserBrandViewModel()
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }
            Client.GetAllBrandsAsync(0);

            Client.GetAllBrandsCompleted += (d, s) =>
            {
                BrandList = s.Result;
            };
            Client.GetAllUsersAsync(0, int.MaxValue, "it.Ename", null, null);
            Client.GetAllUsersCompleted += (d, s) =>
            {
                UsersList    = s.Result;
                SelectedUser = s.Result.FirstOrDefault();
            };

            //Client.GetGenericCompleted += (s, sv) =>
            //{
            //    foreach (var row in sv.Result)
            //    {
            //        var newrow = new TblUserBrandSectionViewModel
            //        {
            //            Aname = row.Aname,
            //            Ename = row.Ename,
            //            Iserial = row.Iserial,
            //            Code = row.Code,
            //            TblLkpBrandSection = row.Iserial,
            //            BrandCode = SelectedBrand.Brand_Code,
            //            TblAuthUser = SelectedUser.Iserial,
            //        };
            //        BrandSectionList.Add(newrow);
            //    }
            //};

            lkpClient.GetTblAllBrandSectionLinkCompleted += (s, sv) =>
            {
                BrandSectionList = new ObservableCollection <TblUserBrandSectionViewModel>();
                foreach (var row in sv.Result)
                {
                    var newrow = new TblUserBrandSectionViewModel
                    {
                        Aname = row.TblLkpBrandSection1.Aname,
                        Ename = row.TblLkpBrandSection1.Ename,
                        TblLkpBrandSection = row.TblLkpBrandSection,
                        Code        = row.TblLkpBrandSection1.Code,
                        BrandCode   = row.TblBrand,
                        TblAuthUser = SelectedUser.Iserial,
                        TblBrandSectionPermissions = row.TblLkpBrandSection1.TblBrandSectionPermissions
                    };
                    BrandSectionList.Add(newrow);
                }
                GetBrandSectionPerUser();
            };

            Client.GetUserSpectialPermissionsAsync();
            Client.GetUserSpectialPermissionsCompleted += (s, sv) =>
            {
                foreach (var row in sv.Result)
                {
                    PermissionList.Add(new TblUserBrandSectionPermissionViewModel
                    {
                        TblAuthPermission = row.Iserial,
                        Ename             = row.Ename,
                    });
                }
            };

            Client.GetTblUserBrandSectionPermissionCompleted += (s, sv) =>
            {
                foreach (var row in PermissionList)
                {
                    row.UpdatedAllowed = false;
                    row.Retail         = row.Technical = row.Financial = row.RetailEnabled = row.TechnicalEnabled = row.FinancialEnabled = row.Checked = false;
                    var brandSectionPermissions =
                        SelectedUserBrandSection.TblBrandSectionPermissions.SingleOrDefault(
                            x => x.TblAuthPermission == row.TblAuthPermission && x.BrandCode == SelectedBrand.Brand_Code);

                    var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission

                                                                       );
                    if (permissionRow != null)
                    {
                        if (brandSectionPermissions != null)
                        {
                            permissionRow.FinancialEnabled = brandSectionPermissions.Financial;
                            permissionRow.TechnicalEnabled = brandSectionPermissions.Technical;
                            permissionRow.RetailEnabled    = brandSectionPermissions.Retail;
                        }
                    }
                }
                foreach (var row in sv.Result)
                {
                    if (SelectedUserBrandSection != null)
                    {
                        var permissionRow = PermissionList.SingleOrDefault(x => x.TblAuthPermission == row.TblAuthPermission && SelectedUserBrandSection.Iserial == row.TblUserBrandSection
                                                                           );
                        if (permissionRow != null)
                        {
                            permissionRow.Checked             = true;
                            permissionRow.TblUserBrandSection = row.Iserial;
                            permissionRow.Retail    = row.Retail;
                            permissionRow.Technical = row.Technical;
                            permissionRow.Financial = row.Financial;
                        }
                    }
                }
            };

            Client.GetTblUserBrandSectionCompleted += (s, sv) =>
            {
                foreach (var row in BrandSectionList)
                {
                    row.UpdatedAllowed = false;
                    row.Checked        = false;
                }
                foreach (var row in sv.Result)
                {
                    var brandSectionRow = BrandSectionList.SingleOrDefault(x => x.TblLkpBrandSection == row.TblLkpBrandSection && x.TblAuthUser == row.TblAuthUser
                                                                           );
                    if (brandSectionRow != null)
                    {
                        brandSectionRow.Iserial = row.Iserial;
                        brandSectionRow.Checked = true;
                    }
                }
            };
        }