Beispiel #1
0
        public static T a_value <T> (this ICreateFakes fake) where T : struct, IConvertible
        {
            var rnd = RandomFactory.GetRandomizer <T>();

            return(rnd.Next());
        }
Beispiel #2
0
        public ResponeDTO <string> AlterMenu(AlterMenuRequest alterMenuRequest)
        {
            if (string.IsNullOrWhiteSpace(alterMenuRequest.MenuName) &&
                string.IsNullOrWhiteSpace(alterMenuRequest.MenuAlias) &&
                string.IsNullOrWhiteSpace(alterMenuRequest.MenuUrl))
            {
                throw new ArgumentException("请求接口参数有错误");
            }

            var respone = new ResponeDTO <string>();

            using (var db = new ShopDbContext())
            {
                Menu parentMenu = null;
                if (!string.IsNullOrWhiteSpace(alterMenuRequest.ParentMenuCode))
                {
                    parentMenu = db.Menu.FirstOrDefault(q => q.MenuCode == alterMenuRequest.ParentMenuCode);
                    if (parentMenu == null)
                    {
                        throw new ArgumentException("接口参数错误");
                    }
                }

                Menu menu;
                if (!string.IsNullOrWhiteSpace(alterMenuRequest.MenuCode))
                {
                    menu = db.Menu.FirstOrDefault(q => q.MenuCode == alterMenuRequest.MenuCode);
                    if (menu == null)
                    {
                        throw new ArgumentException("修改的菜单编码不存在");
                    }
                }
                else
                {
                    menu          = new Menu();
                    menu.MenuCode = RandomFactory.GetRandomizer(6, extensiveCodes: db.Menu.Select(q => q.MenuCode).ToList());
                }
                menu.MenuName        = alterMenuRequest.MenuName;
                menu.MenuStatus      = (Status)alterMenuRequest.MenuStatus;
                menu.MenuAlias       = alterMenuRequest.MenuAlias;
                menu.MenuUrl         = alterMenuRequest.MenuUrl;
                menu.Level           = alterMenuRequest.Level;
                menu.Sort            = alterMenuRequest.Sort;
                menu.MenuIcon        = alterMenuRequest.MenuIcon;
                menu.IsDefaultRouter = alterMenuRequest.IsDefaultRouter;
                menu.ParentMenuCode  = alterMenuRequest.ParentMenuCode;
                menu.Description     = alterMenuRequest.Description;
                menu.ParentMenuName  = parentMenu == null ? "顶级菜单" : parentMenu.MenuName;
                menu.AuditEntity     = new AuditEntity()
                {
                    CreatedOn = DateTime.Now
                };

                if (string.IsNullOrWhiteSpace(alterMenuRequest.MenuCode))
                {
                    db.Menu.Add(menu);
                }
                else
                {
                    db.Menu.Update(menu);
                }
                db.SaveChanges();
                respone.Data = menu.MenuCode;
            }
            return(respone);
        }
Beispiel #3
0
        public static T a_sealed <T>(this ICreateFakes fake, Func <T> creator) where T : class
        {
            var rnd = RandomFactory.GetRandomizer <T>(creator);

            return(rnd.Next());
        }