Пример #1
0
        public RoleAuthViewModel(RoleAuth roleAuth, List <AuthData> allDataRange)
        {
            if (roleAuth == null)
            {
                return;
            }

            this.RoleId   = roleAuth.RoleId;
            this.RoleName = roleAuth.RoleName;
            this.Compcd   = roleAuth.CompCd;
            this.PageAuth = new List <TreeViewNode>();


            #region 功能權限設定

            //目前已設定權限
            var currentAuth = roleAuth.PageAuth.ToDictionary(x => x.GroupName);
            //轉成sitemapNode
            foreach (var item in SiteMenu.FullMenuNode)
            {
                var newItemColl = RecursiveChild(item, null, currentAuth);

                if (newItemColl.Count >= 1)
                {
                    this.PageAuth.AddRange(newItemColl);
                }
            }

            #endregion



            this.UpdateUser = roleAuth.UpdateUser;
            this.UpdateTime = roleAuth.UpdateTime;
        }
        public ActionResult Search(string RoleId, string Compcd)
        {
            try
            {
                var con = new Conditions <DataBase.TSYSROL>();

                con.And(x => x.Comp_Cd == Compcd &&
                        x.Role_Id == RoleId);

                RoleAuth roleAuth = _tsysrolRepo.Get(con);

                if (roleAuth == null)
                {
                    throw new NullReferenceException($"no find data");
                }

                return(View("Edit", new RoleAuthViewModel(roleAuth, new List <AuthData>())
                {
                    WorkType = AuthNodeType.Read
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
            return(View());
        }
        public ActionResult RefreshTreeView(string RoleID, string Compcd)
        {
            JsonResult Result   = new JsonResult();
            RoleAuth   roleAuth = new RoleAuth();

            try
            {
                var con = new Conditions <DataBase.TSYSROL>();

                con.And(x => x.Comp_Cd == Compcd &&
                        x.Role_Id == RoleID);

                roleAuth = _tsysrolRepo.Get(con);

                if (roleAuth == null)
                {
                    throw new NullReferenceException($"no find data");
                }

                Result.Data = new MemberSetViewModel(roleAuth);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
            }
            return(Json(Result));
        }
Пример #4
0
        protected override void OnLoad(EventArgs e)
        {
            if (RoleAuth.CheckLoggedInUserSession(RoleAuth.UserRoles.Admin))
            {
                //TODO
            }
            else
            {
                System.Web.HttpContext.Current.Response.Redirect("~/Views/Authentication/Login");
            }

            // Be sure to call the base class's OnLoad method!
            base.OnLoad(e);
        }
Пример #5
0
        public MemberSetViewModel(RoleAuth role)
        {
            this.PageAuth = new List <TreeViewNode>();

            //目前已設定權限
            var currentAuth = role.PageAuth.ToDictionary(x => x.GroupName);


            //轉成sitemapNode
            foreach (var item in SiteMenu.FullMenuNode)
            {
                var newItemColl = RecursiveChild(item, null, currentAuth);

                if (newItemColl.Count >= 1)
                {
                    this.PageAuth.AddRange(newItemColl);
                }
            }
        }
Пример #6
0
        public void Initializar()
        {
            try
            {
                if (_db.Database.GetPendingMigrations().Count() > 0)
                {
                    _db.Database.Migrate();
                }
            }
            catch (Exception ex)
            {
            }

            if (_roleManager.RoleExistsAsync(SD.AdminUser).GetAwaiter().GetResult())
            {
                return;
            }

            // Creating User Roles
            _roleManager.CreateAsync(new IdentityRole(SD.AdminUser)).GetAwaiter().GetResult();
            _roleManager.CreateAsync(new IdentityRole(SD.SupervisorUser)).GetAwaiter().GetResult();
            _roleManager.CreateAsync(new IdentityRole(SD.BnasStoreUser)).GetAwaiter().GetResult();
            _roleManager.CreateAsync(new IdentityRole(SD.YaseenStoreUser)).GetAwaiter().GetResult();

            // Create Admin User
            _userManager.CreateAsync(new ApplicationUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                PhoneNumber    = "1233456456",
                FirstName      = "Bnas admin"
            }, "Qwer!234"
                                     ).GetAwaiter().GetResult();

            // assign role to admin user
            IdentityUser user = _db.ApplicationUser.FirstOrDefaultAsync(u => u.Email == "*****@*****.**").GetAwaiter().GetResult();

            _userManager.AddToRoleAsync(user, SD.AdminUser).GetAwaiter().GetResult();

            // Creating Price Types (Retail price and wholesales price)
            PricingType RPrices = new PricingType
            {
                PriceType = SD.RetailPrice
            };

            PricingType WPrices = new PricingType
            {
                PriceType = SD.WholePrice
            };

            _db.PricingType.Add(RPrices);
            _db.PricingType.Add(WPrices);

            // Create Authentication Roles for Supervisor
            RoleAuth Auth = new RoleAuth
            {
                RoleName      = SD.SupervisorUser,
                AppTransReq   = false,
                CreateInGoods = false
            };

            _db.RoleAuth.Add(Auth);

            // Create Wh types (showrooms and store rooms)
            WhType ShowRoom = new WhType
            {
                Type = SD.ShowRoom
            };

            WhType StoreRoom = new WhType
            {
                Type = SD.StoreRoom
            };

            _db.WhType.Add(ShowRoom);
            _db.WhType.Add(StoreRoom);


            // save all changes
            _db.SaveChangesAsync();
        }
Пример #7
0
        internal protected virtual int AddOrUpdate(int roleId, List <AuthType> list, FileContext db)
        {
            int count = 0;

            if (list != null && roleId > 0)
            {
                list = new List <AuthType>(list);
                db.Configuration.AutoDetectChangesEnabled = true;
                var             old = db.RoleAuth.Where(q => q.RoleId == roleId).ToList();
                List <RoleAuth> del = new List <RoleAuth>();
                while (old.Count > 0)
                {
                    var m = old[0];
                    old.Remove(m);
                    if (list.Contains(m.Type))
                    {
                        list.Remove(m.Type);
                    }
                    else
                    {
                        del.Add(m);
                    }
                }
                db.AddCommitCallback(() =>
                {
                    this.GetCache <IRoleAuthCache>().Remove(roleId);
                });
                while (list.Count > 0)
                {
                    var auth = list[0];
                    list.Remove(auth);
                    RoleAuth m = null;
                    if (del.Count > 0)
                    {
                        m = del[0];
                        del.Remove(m);
                    }
                    else
                    {
                        m = new RoleAuth()
                        {
                            RoleId = roleId
                        };
                    }
                    m.Type = auth;
                    if (m.Id == 0)
                    {
                        db.RoleAuth.Add(m);
                    }
                    count += db.SaveChanges();
                }

                del.ForEach(m =>
                {
                    db.Entry(m).State = System.Data.Entity.EntityState.Deleted;
                    count            += db.SaveChanges();
                });
            }

            return(count);
        }
Пример #8
0
        /// <summary>
        /// [server 更新使用者資訊]
        /// </summary>
        /// <param name="user"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public bool Update(UserBase User, RoleAuth Role)
        {
            #region 找到對應的使用者

            var uCon = new Conditions <DataBase.TUSRMST>();

            uCon.And(x => x.Comp_Cd == User.CompCd &&
                     x.User_Id == User.UserId);


            //uCon.Include(x => x.TSYSROL);

            Tusrmst user = _userRepo.Get(uCon);


            if (user == null)
            {
                throw new NullReferenceException($"[ERROR]=>找不到對應的使用者資訊,公司代號:{User.CompCd},使用者ID:{User.UserId}");
            }


            #endregion

            #region 找到對應權限

            var rCon = new Conditions <DataBase.TSYSROL>();

            rCon.And(x => x.Comp_Cd == Role.CompCd &&
                     x.Role_Id == Role.RoleId);

            RoleAuth role = _aspRoleRepo.Get(rCon);

            if (role == null)
            {
                throw new NullReferenceException($"[ERROR]=>找不到對應的權限資訊,公司代號:{User.CompCd},權限ID:{User.RoleId}");
            }


            #endregion

            #region 組合物件

            List <AuthItem> pageAuth = CulcPageAuth(role.PageAuth, User.PageAuth);

            user.RoleId = role.RoleId;

            user.PageAuth = pageAuth != null?JsonConvert.SerializeObject(pageAuth) : string.Empty;


            #endregion

            #region 更新資料

            uCon.Allow(x => x.Role_Id,
                       x => x.PageAuth);


            if (!_userRepo.Update(uCon, user))
            {
                throw new Exception("[ERROR]=>更新使用者資訊失敗");
            }

            #endregion

            return(true);
        }
        public ActionResult ModifyMemberAuth(MemberSetViewModel model)
        {
            Boolean isSuccess = false;

            try
            {
                var compcd = model?.Compcd ?? model.Compcd;
                var user   = new UserBase()
                {
                    CompCd   = compcd,
                    UserId   = model.UserID,
                    RoleAuth = new RoleAuth()
                    {
                        RoleName = model.RoleName
                    },
                    PageAuth = (model?.PageAuth == null ? new List <AuthItem>() : model.PageAuth.Select(x => new AuthItem()
                    {
                        GroupName = x.id,
                        AuthType = x.AuthType
                    })
                                .ToList()),
                };

                var con = new Conditions <DataBase.TSYSROL>();

                con.And(x => x.Comp_Cd == compcd &&
                        x.Role_Id == model.RoleName);
                var roleAuth = _tsysrolRepo.Get(con);

                if (roleAuth == null)
                {
                    throw new Exception("[ERROR]=>該腳色未設定權限");
                }

                var role = new RoleAuth()
                {
                    CompCd     = compcd,
                    RoleId     = model.RoleName,
                    UpdateTime = DateTime.Now,
                    PageAuth   = roleAuth.PageAuth
                };

                isSuccess = _aspUserService.Update(user, role);

                return(Json(new JsonResult()
                {
                    Data = new
                    {
                        IsSuccess = true,
                        Message = $"修改帳號資料:{(isSuccess ? "成功" : "失敗")}"
                    }
                }));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(Json(new JsonResult()
                {
                    Data = new
                    {
                        IsSuccess = false,
                        Message = $"修改帳號資料失敗,原因:{ex.Message}"
                    }
                }));
            }
        }
        public ActionResult ModifyMasterAuth(RoleAuthViewModel model)
        {
            Boolean isSuccess = false;

            try
            {
                var con = new Conditions <DataBase.TSYSROL>();

                var compcd = model?.Compcd ?? string.Empty;

                con.And(x => x.Comp_Cd == compcd &&
                        x.Role_Id == model.RoleId);

                RoleAuth roleAuth = _tsysrolRepo.Get(con);

                if (roleAuth == null)
                {
                    throw new NullReferenceException($"no find data");
                }

                List <AuthItem> pageAuth = model.PageAuth == null ? new List <AuthItem>() :
                                           model.PageAuth.Select(x => new AuthItem()
                {
                    GroupName = x.id, AuthType = x.AuthType
                }).ToList();
                Tsysrol updaterole = new Tsysrol()
                {
                    RoleId   = model.RoleId,
                    RoleName = model.RoleName,
                    CompCd   = model.Compcd,
                    PageAuth = pageAuth != null?JsonConvert.SerializeObject(pageAuth) : string.Empty,
                                   UpdateDate = DateTime.Now,
                                   UpdateUser = User.Identity.Name,
                };

                con.Allow(y => y.Role_Name,
                          y => y.PageAuth,
                          y => y.Update_Date,
                          y => y.Update_User);

                isSuccess = _uptsysrolRepo.Update(con, updaterole);

                MvcSiteMapProvider.SiteMaps.ReleaseSiteMap();

                return(Json(new JsonResult()
                {
                    Data = new
                    {
                        IsSuccess = isSuccess,
                        Message = $"修改權限:{(isSuccess ? "成功" : "失敗")}"
                    }
                }));
            }
            catch (Exception ex)
            {
                return(Json(new JsonResult()
                {
                    Data = new
                    {
                        IsSuccess = isSuccess,
                        Message = $"修改權限:{(isSuccess ? "成功" : "失敗")}"
                    }
                }));
            }
        }
        public static string SaveNews(ContentPlaceHolder _refContentPlaceHolder)
        {
            try
            {
                if (_refContentPlaceHolder.Controls.Count > 0)
                {
                    TextBox       txt         = null;
                    DropDownList  ddl         = null;
                    NewsMaster    _NewsMaster = new NewsMaster();
                    List <string> lstTags     = new List <string>();

                    Guid _newsID = Guid.NewGuid();

                    _NewsMaster.NewsId         = _newsID;
                    _NewsMaster.IsDel          = false;
                    _NewsMaster.Userid         = RoleAuth.GetUserID();
                    _NewsMaster.NewsCreateDate = DateTime.Now;

                    foreach (var item in _refContentPlaceHolder.Controls)
                    {
                        if (item is DropDownList)
                        {
                            ddl = item as DropDownList;

                            if (ddl.ID == "ddl_NewsCategory")
                            {
                                if (ddl.SelectedItem.Value == "-1")
                                {
                                    // validate the data and return message
                                    throw new Exception("there is no category selected!");
                                }
                                else
                                {
                                    // creating the NewsMaster data
                                    _NewsMaster.CategoryId = int.Parse(ddl.SelectedItem.Value.Trim());
                                }
                            }
                            else if (ddl.ID == "ddl_newsSubCategory")
                            {
                                ddl = item as DropDownList;

                                if (ddl.SelectedItem.Value == "-1")
                                {
                                    // validate the data and return message
                                    throw new Exception("there is no sub category selected!");
                                }
                                else
                                {
                                    // creating the NewsMaster data
                                    _NewsMaster.SubCategoryId = int.Parse(ddl.SelectedItem.Value.Trim());
                                }
                            }
                        }
                        else if (item is TextBox)
                        {
                            txt = item as TextBox;

                            if (txt.ID == "txtTitle")
                            {
                                if (txt.Text == "")
                                {
                                    // validate the data and return message
                                    throw new Exception("please enter title!");
                                }
                                else
                                {
                                    // creating the NewsMaster data
                                    _NewsMaster.NewsTitle = txt.Text.Trim();
                                }
                            }
                            else if (txt.ID == "txtNewsDate")
                            {
                                if (txt.Text == "")
                                {
                                    // validate the data and return message
                                    throw new Exception("please select date!");
                                }
                                else
                                {
                                    // creating the NewsMaster data
                                    _NewsMaster.NewsDate = DateTime.Parse(txt.Text.Trim());
                                }
                            }
                            else if (txt.ID == "txtAuthor")
                            {
                                if (txt.Text == "")
                                {
                                    // validate the data and return message
                                    throw new Exception("please enter Author Name!");
                                }
                                else
                                {
                                    // creating the NewsMaster data
                                    _NewsMaster.NewsAuthor = txt.Text.Trim();
                                }
                            }
                            else if (txt.ID == "txtContent")
                            {
                                if (txt.Text == "")
                                {
                                    // validate the data and return message
                                    throw new Exception("please enter news content!");
                                }
                                else
                                {
                                    // creating the NewsMaster data
                                    _NewsMaster.NewsContent = txt.Text;
                                }
                            }
                            else if (txt.ID == "txtTags")
                            {
                                if (txt.Text == "")
                                {
                                    // validate the data and return message
                                    lstTags = null;
                                }
                                else
                                {
                                    // creating the NewsMaster data
                                    string[] tags = txt.Text.Trim().Split(',').ToArray();
                                    for (int i = 0; i < tags.Length; i++)
                                    {
                                        lstTags.Add(tags[i].Trim());
                                    }
                                }
                            }
                        }
                    }

                    // Save into NewsMaster Table
                    int t = EDM_NewsMaster.SaveNews(_NewsMaster);
                    if (t > 0)
                    {
                        if (lstTags != null && lstTags.Count > 0)
                        {
                            for (int i = 0; i < lstTags.Count; i++)
                            {
                                t = BAL_NewsTags.SaveNewsTags(_newsID, lstTags[i].Trim());
                            }
                        }
                        else if (lstTags == null)
                        {
                            //TODO
                        }

                        return("Success");
                    }
                    else
                    {
                        return("Faliure");
                    }
                }
                else
                {
                    throw new Exception("Null Data");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #12
0
        public static int SaveNewsTags(Guid newsID, string newsTag)
        {
            int t = EDM_NewsTags.SaveNewsTags(newsID, newsTag, RoleAuth.GetUserID());

            return(t);
        }