コード例 #1
0
        protected void gvUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            int userId = 0;

            userId = int.Parse(gvUsers.SelectedRow.Cells[1].Text);
            UB     = UBM.GetUserBrandByUserId(userId);
            if (UB != null)
            {
                lblAssignedbrand.Text      = "CURENT BRAND: " + UB.BrandName;
                checkReAssignBrand.Visible = true;
                ddListBrands.Enabled       = false;
                checkAll.Enabled           = false;
                hfUserBrandId.Value        = UB.RecordNumber.ToString();
            }
            else
            {
                lblAssignedbrand.Text      = "NO ASSIGN BRAND";
                checkReAssignBrand.Visible = false;
                ddListBrands.Enabled       = true;
                checkAll.Enabled           = true;
                hfUserBrandId.Value        = "0";
            }

            lblUser.Text = "User Name: " + gvUsers.SelectedRow.Cells[2].Text;
        }
コード例 #2
0
ファイル: UserVM.cs プロジェクト: almutama/fashionDRP
        private OPResult Update(SysUserBO user)
        {
            var roleIDs            = RolesCurrentUserCover.Select(rs => rs.ID);//加上ToList()在下面执行时就抛出Contains不支持的异常,坑爹
            List <SysUserRole> urs = new List <SysUserRole>();

            foreach (var rs in user.Roles)
            {
                SysUserRole ur = new SysUserRole
                {
                    UserId    = user.ID,
                    RoleId    = rs.ID,
                    CreatorID = VMGlobal.CurrentUser.ID
                };
                urs.Add(ur);
            }

            var brandIDs         = VMGlobal.PoweredBrands.Select(bs => bs.ID);
            List <UserBrand> ubs = new List <UserBrand>();

            foreach (var bs in user.Brands)
            {
                UserBrand ub = new UserBrand
                {
                    UserID    = user.ID,
                    BrandID   = bs.ID,
                    CreatorID = VMGlobal.CurrentUser.ID
                };
                ubs.Add(ub);
            }

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    LinqOP.Update <SysUser>(user);
                    LinqOP.Delete <SysUserRole>(ur => roleIDs.Contains(ur.RoleId) && ur.UserId == user.ID);
                    VMGlobal.SysProcessQuery.LinqOP.Delete <UserBrand>(ub => brandIDs.Contains(ub.BrandID) && ub.UserID == user.ID);
                    LinqOP.Add <SysUserRole>(urs);
                    VMGlobal.SysProcessQuery.LinqOP.Add <UserBrand>(ubs);
                    scope.Complete();
                    return(new OPResult {
                        IsSucceed = true, Message = "更新成功."
                    });
                }
                catch (Exception e)
                {
                    return(new OPResult {
                        IsSucceed = false, Message = "更新失败,失败原因:\n" + e.Message
                    });
                }
            }
        }
コード例 #3
0
 public void Save(UserBrand UserBrand)
 {
     using (DbManager db = new DbManager())
     {
         if (UserBrand.RecordNumber > 0)
         {
             Accessor.Query.Update(db, UserBrand);
         }
         else
         {
             Accessor.Query.Insert(db, UserBrand);
         }
     }
 }
コード例 #4
0
        protected void btnAssign_Click(object sender, EventArgs e)
        {
            UserBrand UserBrand = new UserBrand();

            if (hfUserBrandId.Value != "0")
            {
                UserBrand.RecordNumber = int.Parse(hfUserBrandId.Value);
            }
            if (checkAll.Checked == true)
            {
                UserBrand.BrandName = "ALL";
            }
            else
            {
                UserBrand.BrandName = ddListBrands.SelectedValue;
            }
            UserBrand.UserId       = int.Parse(gvUsers.SelectedRow.Cells[1].Text);
            UserBrand.DateRecorded = DateTime.UtcNow;
            UBM.Save(UserBrand);
            lblSuccessSaved_ModalPopupExtender.Show();
        }
コード例 #5
0
        public override OPResult AddOrUpdate(ProBrand entity)
        {
            int id = entity.ID;

            using (TransactionScope scope = new TransactionScope())
            {
                var result = base.AddOrUpdate(entity);
                if (result.IsSucceed)
                {
                    if (id == default(int))
                    {
                        var ub = new UserBrand {
                            UserID = VMGlobal.CurrentUser.ID, BrandID = entity.ID, CreateTime = DateTime.Now, CreatorID = VMGlobal.CurrentUser.ID
                        };
                        var ob = new OrganizationBrand {
                            OrganizationID = VMGlobal.CurrentUser.OrganizationID, BrandID = entity.ID, CreateTime = DateTime.Now, CreatorID = VMGlobal.CurrentUser.ID
                        };
                        LinqOP.Add <UserBrand>(ub);
                        LinqOP.Add <OrganizationBrand>(ob);
                    }
                    scope.Complete();

                    var brand = VMGlobal.PoweredBrands.Find(o => o.ID == entity.ID);
                    if (brand == null)
                    {
                        VMGlobal.PoweredBrands.Add(entity);
                    }
                    else
                    {
                        int index = VMGlobal.PoweredBrands.IndexOf(brand);
                        VMGlobal.PoweredBrands[index] = entity;
                    }
                }
                return(result);
            }
        }
コード例 #6
0
        public ActionResult Register(User newUser, short roles, short brands)
        {
            var userRole = new UserRole
            {
                RoleId      = roles,
                DateCreated = DateTime.Now
            };

            var userBrand = new UserBrand
            {
                BrandId     = brands,
                DateCreated = DateTime.Now
            };

            newUser.UserRoles.Add(userRole);
            newUser.UserBrands.Add(userBrand);
            newUser.DateCreated  = DateTime.Now;
            newUser.DateModified = DateTime.Now;
            newUser.Active       = true;

            var userId = Repository.SaveUser(newUser);

            return(RedirectToAction("Users"));
        }
コード例 #7
0
ファイル: UserVM.cs プロジェクト: almutama/fashionDRP
        //用户对应的各种数据集合,避免在UI绑定时频繁操作数据库
        //private void RefreshAttachData()
        //{
        //    var users = (List<SysUser>)Users.SourceCollection;
        //    var uIDs = users.Select<SysUser, int>(u => u.ID);

        //    var urs = _query.QueryProvider.GetTable<SysUserRole>("SysUserRole");
        //    var queryUR = from ur in urs where uIDs.Contains(ur.UserId) select ur;
        //    UserRoles = queryUR.ToList();

        //    var ubs = _queryDistribution.QueryProvider.GetTable<UserBrand>("UserBrand");
        //    var queryUB = from ub in ubs where uIDs.Contains(ub.UserID) select ub;
        //    UserBrands = queryUB.ToList();

        //    var oIDs = users.Select<SysUser, int>(u => u.OrganizationID);
        //    Organizations = _query.LinqOP.Search<SysOrganization>(o => oIDs.Contains(o.ID)).ToList();
        //}

        private OPResult Add(SysUserBO user)
        {
            int?userpointlimit = null;

            try
            {
                userpointlimit = this.GetUserPointLimit();
                if (userpointlimit == null)
                {
                    return new OPResult {
                               IsSucceed = false, Message = "保存失败,失败原因:\n无法确认用户点数是否存在上限,请联系软件公司。"
                    }
                }
                ;
                if ((userpointlimit != -1) && userpointlimit <= LinqOP.Search <SysUser>().Count())
                {
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n超过用户点数限制,若要增加用户点数,请联系软件公司。"
                    });
                }
            }
            catch (Exception e)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                });
            }
            string oginalPWD = user.Password;

            user.CreatorID = VMGlobal.CurrentUser.ID;
            user.Password  = oginalPWD.ToMD5String();
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    int id = LinqOP.Add <SysUser, int>(user, r => r.ID);
                    user.ID = id;
                    List <SysUserRole> urs = new List <SysUserRole>();
                    foreach (var r in user.Roles)
                    {
                        SysUserRole ur = new SysUserRole
                        {
                            UserId    = id,
                            RoleId    = r.ID,
                            CreatorID = VMGlobal.CurrentUser.ID
                        };
                        urs.Add(ur);
                    }
                    LinqOP.Add <SysUserRole>(urs);

                    List <UserBrand> ubs = new List <UserBrand>();
                    foreach (var b in user.Brands)
                    {
                        UserBrand ub = new UserBrand
                        {
                            UserID    = id,
                            BrandID   = b.ID,
                            CreatorID = VMGlobal.CurrentUser.ID
                        };
                        ubs.Add(ub);
                    }
                    VMGlobal.SysProcessQuery.LinqOP.Add <UserBrand>(ubs);
                    scope.Complete();
                    return(new OPResult {
                        IsSucceed = true, Message = "保存成功."
                    });
                }
                catch (Exception e)
                {
                    user.ID       = default(int);
                    user.Password = oginalPWD;
                    return(new OPResult {
                        IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message
                    });
                }
            }
        }
コード例 #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Brand brand = Brand.Get(WebUtils.GetIntRequestParam("BrandId", 0));

                if (!brand.IsNull)
                {
                    // Populate the user interface
                    FullBrandNameTextBox.Text    = brand.Name;
                    ShortBrandNameTextBox.Text   = brand.ShortName;
                    ApplicationNameTextBox.Text  = brand.ApplicationName;
                    OrganisationNameTextBox.Text = brand.OrganisationName;
                    WebsiteUrlTextBox.Text       = brand.WebsiteUrl;
                    EmailFromTextBox.Text        = brand.EmailFrom;
                    AllowBrandSelectionDuringRegistrationCheckBox.Checked = brand.IsBrandSelectionAllowed;
                    LoginPageUpperCopyTextBox.Text           = brand.LoginPageUpperCopy;
                    LoginPageLowerCopyTextBox.Text           = brand.LoginPageLowerCopy;
                    DefaultUsageRestrictionsCopyTextBox.Text = brand.DefaultUsageRestrictionsCopy;
                    MyAccountCopyTextBox.Text            = brand.MyAccountCopy;
                    AdminCopyTextBox.Text                = brand.AdminCopy;
                    TermsConditionsCopyTextBox.Text      = brand.TermsConditionsCopy;
                    PrivacyPolicyCopyTextBox.Text        = brand.PrivacyPolicyCopy;
                    EnableDirectDownloadCheckBox.Checked = brand.DirectDownloadEnabled;

                    if (DisabledPoweredByFooterCheckBox != null)
                    {
                        DisabledPoweredByFooterCheckBox.Checked = brand.DisablePoweredByLogo;
                    }

                    // Brand folder
                    string brandFolder    = string.Format("~/Brands/Brand_{0}/", brand.BrandId);
                    string absBrandFolder = Server.MapPath(brandFolder);

                    if (Directory.Exists(absBrandFolder))
                    {
                        // Get the watermark image extension
                        string extension = (from f in Directory.GetFiles(absBrandFolder)
                                            where (Path.GetFileName(f) ?? string.Empty).StartsWith("watermark")
                                            select Path.GetExtension(f)).FirstOrDefault();

                        // Set the watermark image url
                        PreviewWatermarkImage.ImageUrl = string.Format("{0}watermark{1}", brandFolder, extension);

                        // Hide preview for non-existent watermark
                        WatermarkImageWrapper.Visible = File.Exists(Server.MapPath(PreviewWatermarkImage.ImageUrl));
                    }

                    // UI folder relative path
                    string uiPath = Path.Combine(absBrandFolder, "UI");

                    // Setup UI management controls
                    BrandFilePackActionPanel.Visible       = Directory.Exists(uiPath);
                    BrowseBrandFolderHyperLink.NavigateUrl = string.Concat(brandFolder, "UI/");
                    EditBrandFilesHyperLink.NavigateUrl    = "~/Admin/Utils/SkinEditor.aspx?BrandId=" + brand.BrandId;

                    // Count assets assigned to this brand
                    AssetFinder finder1 = new AssetFinder {
                        BrandId = brand.BrandId.GetValueOrDefault()
                    };
                    int count = Asset.GetCount(finder1);

                    // Count users assigned to this brand if there are no assets assigned to it
                    // We only need to know that NO users or assets are assigned, so no point doing
                    // this check and hammering the database if we already know there are assets
                    if (count == 0)
                    {
                        UserBrandFinder finder2 = new UserBrandFinder {
                            BrandId = brand.BrandId.GetValueOrDefault()
                        };
                        count = UserBrand.GetCount(finder2);
                    }

                    // Only show the delete button if there are no users or assets
                    // assigned.  Otherwise, the brand cannot be deleted.
                    DeleteButton.Visible         = (count == 0);
                    DeleteButton.CommandArgument = brand.BrandId.ToString();
                }
            }
        }