public override bool ValidateUser(string username, string password)
        {
            bool isValid = false;

            using (EnterpriseContext _db = new EnterpriseContext())
            {
                try
                {
                    User user = (from u in _db.Users
                                 where u.Email == username
                                 select u).FirstOrDefault();

                    if (user != null && Crypto.VerifyHashedPassword(user.Password, password))
                    {
                        isValid = true;
                    }
                }
                catch
                {
                    isValid = false;
                }
            }

            return(isValid);
        }
Ejemplo n.º 2
0
        public override bool IsUserInRole(string username, string roleName)
        {
            bool outputResult = false;

            // Находим пользователя
            using (EnterpriseContext _db = new EnterpriseContext())
            {
                try
                {
                    // Получаем пользователя
                    User user = (from u in _db.Users
                                 where u.Email == username
                                 select u).FirstOrDefault();
                    if (user != null)
                    {
                        // получаем роль
                        Role userRole = _db.Roles.Find(user.RoleId);

                        //сравниваем
                        if (userRole != null && userRole.Name == roleName)
                        {
                            outputResult = true;
                        }
                    }
                }
                catch
                {
                    outputResult = false;
                }
            }
            return(outputResult);
        }
Ejemplo n.º 3
0
        public void Select_WithCallBack_Refresh__With_Key_Customers()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers")
                .WithCallBack(e => new { e.ID, e.RV, e.LastName, e.FirstName })
                .Refresh(context.Customers);

                connection.Close();
            }

            context.Customers[0].NationalIdentityNumber = "9999999999";

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers")
                .WithCallBack(e => new { e.ID, e.NationalIdentityNumber })
                .Refresh(context.Customers);

                connection.Close();
            }
        }
Ejemplo n.º 4
0
        public override string[] GetRolesForUser(string email)
        {
            string[] role = new string[] { };
            using (EnterpriseContext _db = new EnterpriseContext())
            {
                try
                {
                    // Получаем пользователя
                    User user = (from u in _db.Users
                                 where u.Email == email
                                 select u).FirstOrDefault();
                    if (user != null)
                    {
                        // получаем роль
                        Role userRole = _db.Roles.Find(user.RoleId);

                        if (userRole != null)
                        {
                            role = new string[] { userRole.Name };
                        }
                    }
                }
                catch
                {
                    role = new string[] { };
                }
            }
            return(role);
        }
        public MembershipUser CreateUser(string email, string password)
        {
            MembershipUser membershipUser = GetUser(email, false);

            if (membershipUser == null)
            {
                try
                {
                    using (EnterpriseContext _db = new EnterpriseContext())
                    {
                        User user = new User();
                        user.Email        = email;
                        user.Password     = Crypto.HashPassword(password);
                        user.CreationDate = DateTime.Now;

                        if (_db.Roles.Find(2) != null)
                        {
                            user.RoleId = 2;
                        }

                        _db.Users.Add(user);
                        _db.SaveChanges();
                        membershipUser = GetUser(email, false);
                        return(membershipUser);
                    }
                }
                catch
                {
                    return(null);
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
        public override void CreateRole(string roleName)
        {
            Role newRole = new Role()
            {
                Name = roleName
            };
            EnterpriseContext db = new EnterpriseContext();

            db.Roles.Add(newRole);
            db.SaveChanges();
        }
Ejemplo n.º 7
0
        public void Select_WithoutCallBack_Fill_Customers()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers")
                .Fill(context.Customers);

                connection.Close();
            }
        }
Ejemplo n.º 8
0
        public void Select_WithCallBack_Products()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Product>()
                .Select("select * from Products")
                .WithCallBack(e => new { e.ID, e.Name, e.Manufacturer, e.Length, e.Width, e.Height, e.Weight, e.Color, e.Power, e.EnergyEfficiency, e.Material, e.Quality, e.Kind, e.Image, e.RV })
                .Fill(context.Products);

                connection.Close();
            }
        }
Ejemplo n.º 9
0
        public void Select_WithCallBack_OrderDetails()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <OrderDetail>()
                .Select("select * from OrderDetails")
                .WithCallBack(e => new { e.ID, e.RV, e.Amount, e.Fee, e.OrderID })                                  // OrderID is not null column, therefore it cann't be omitted in query, and must be loaded in model
                .Fill(context.OrderDetails);

                connection.Close();
            }
        }
Ejemplo n.º 10
0
        public void Select_WithCallBack_Orders()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Order>()
                .Select("select * from Orders")
                .WithCallBack(e => new { e.ID, e.CustomerID, e.ReceiveDate, e.ShippingDate, e.RV })
                .Fill(context.Orders);

                connection.Close();
            }
        }
Ejemplo n.º 11
0
        public void Select_WithCallBack_Merge_Without_Key_Customers()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select 'Extra' as ExtraColumn, *, 'Extra' as ExtraColumn from Customers")
                .WithCallBack(e => new { e.RV, e.LastName, e.FirstName })
                .Merge(context.Customers);

                connection.Close();
            }
        }
Ejemplo n.º 12
0
        public void Select_WithCallBack_Fill_Customers_FiveTime()
        {
            EnterpriseContext context1 = new EnterpriseContext();
            EnterpriseContext context2 = new EnterpriseContext();
            EnterpriseContext context3 = new EnterpriseContext();
            EnterpriseContext context4 = new EnterpriseContext();
            EnterpriseContext context5 = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select * from Customers")
                .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.NationalIdentityNumber, e.RV })                                  // Same As context4
                .Fill(context1.Customers);

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select * from Customers")
                .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.RV })                                  // Same As context5
                .Fill(context2.Customers);

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select * from Customers")
                .WithCallBack(e => new { e.ID, e.RV, e.FirstName, e.LastName, e.NationalIdentityNumber })
                .Fill(context3.Customers);

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select * from Customers")
                .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.NationalIdentityNumber, e.RV })                                  // Same As context1
                .Fill(context4.Customers);

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Select("select * from Customers")
                .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.RV })                                  // Same As context2
                .Fill(context5.Customers);

                connection.Close();
            }
        }
Ejemplo n.º 13
0
        public void SelectAsync_Prepared_With_Transaction_With_Parameter_With_CallBack()
        {
            EnterpriseContext context = new EnterpriseContext();

            var consideredCustomers = UserDefinedTableTypeCreator.Create("BigIntIDs", () => new { ID = default(long) })
                                      .Add(new { ID = 15L })
                                      .Add(new { ID = 19L });

            EntityDatabaseConnection connection = GetConnection();

            var t = EntityDatabase <EnterpriseContext> .Connect(connection)
                    .Transaction(IsolationLevel.Snapshot)
                    .Select(@"select * 
                                                               from Customers c
                                                                 inner join @ConsideredCustomers cc on cc.ID = c.ID
                                                           
                                                               declare @Orders table (ID bigint, CustomerID int, ShippingDate date, RV binary(8))
                                                           
                                                               insert into @Orders
                                                                 select o.ID, o.CustomerID, o.ShippingDate, o.RV
                                                               from Orders o
                                                                 inner join @ConsideredCustomers cc on cc.ID = o.CustomerID
                                                               where o.ReceiveDate > parse('1398/02/01' as date using 'fa-IR')
                                                           
                                                               select * 
                                                               from @Orders o
                                                               order by o.ShippingDate

                                                               select *
                                                               from OrderDetails od
                                                                 inner join @Orders o on o.ID = od.OrderID

                                                               select * 
                                                               from Products
                                                               where ID = @ProductID")
                    .WithParameters(new { ProductID = 6005, ConsideredCustomers = consideredCustomers })
                    .To(context)
                    .Fill <Customer>(e => new { e.LastName, e.NationalIdentityNumber, e.FirstName, e.ID })
                    .Fill <Order>(e => new { e.ShippingDate, e.RV, e.ID })
                    .Fill <OrderDetail>(e => new { e.Amount, e.RV, e.Fee, e.ID, e.OrderID })                                 // OrderID is not null column, therefore it cann't be omitted in query, and must be loaded in model
                    .Fill <Product>(e => new { e.ID, e.Name, e.Manufacturer })
                    .ExecuteAsync();

            t.Wait();
        }
Ejemplo n.º 14
0
        public void Select_Prepared_Without_Parameter_With_CallBack()
        {
            EnterpriseContext context = new EnterpriseContext();


            using (EntityDatabaseConnection connection = GetConnection())
            {
                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Select(@"select * from Customers
                                                           select * from Orders
                                                           select * from Products")
                .To(context)
                .Fill <Customer>(e => new { e.LastName, e.NationalIdentityNumber, e.FirstName, e.ID })
                .Fill <Order>(e => new { e.RV, e.ID, e.CustomerID })
                .Fill <Product>(e => new { e.ID, e.Name, e.Manufacturer })
                .Execute();
            }
        }
Ejemplo n.º 15
0
        public void Select_Prepared_Without_Parameter_Without_CallBack()
        {
            EnterpriseContext context = new EnterpriseContext();


            using (EntityDatabaseConnection connection = GetConnection())
            {
                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Select(@"select * from Customers
                                                           select * from Orders
                                                           select * from Products")
                .To(context)
                .Fill <Customer>()
                .Fill <Order>()
                .Fill <Product>()
                .Execute();
            }
        }
Ejemplo n.º 16
0
        public void Select_With_Transaction_Without_CallBack()
        {
            EnterpriseContext context = new EnterpriseContext();


            using (EntityDatabaseConnection connection = GetConnection())
            {
                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Transaction(IsolationLevel.Snapshot)
                .Select(@"select * from Customers
                                                           select * from Orders
                                                           select * from Products")
                .To(context)
                .Fill <Customer>()
                .Fill <Order>()
                .Fill <Product>()
                .Execute();
            }
        }
Ejemplo n.º 17
0
        public void Select_Prepared_WithoutParameters_WithCallBack_Fill_Customers()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Prepared()
                .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn 
                                                           from Customers c")
                .WithCallBack(e => new { e.ID, e.FirstName, e.LastName, e.NationalIdentityNumber, e.RV })
                .Fill(context.Customers);

                connection.Close();
            }
        }
Ejemplo n.º 18
0
        public void Select_Prepared_WithParameters_WithoutCallBack_Fill_Customers()
        {
            EnterpriseContext context = new EnterpriseContext();

            using (EntityDatabaseConnection connection = GetConnection())
            {
                connection.Open();

                EntityDatabase <EnterpriseContext> .Connect(connection)
                .Table <Customer>()
                .Prepared()
                .WithParameters(new { CustomerID = 16 })
                .Select(@"select 'Extra' as ExtraColumn, c.*, 'Extra' as ExtraColumn 
                                                           from Customers c
                                                           where c.ID = @CustomerID")
                .Fill(context.Customers);

                connection.Close();
            }
        }
Ejemplo n.º 19
0
        public void SelectAsync_Prepared_With_Transaction_Without_Parameter_Without_CallBack_BigData()
        {
            EnterpriseContext context = new EnterpriseContext();

            EntityDatabaseConnection connection = GetConnection();

            var t = EntityDatabase <EnterpriseContext> .Connect(connection)
                    .Transaction(IsolationLevel.Snapshot)
                    .Select(@"select * 
                                                               from Customers c
                                                               
                                                               select * 
                                                               from Customers c
                                                               
                                                               select *
                                                               from Customers c")
                    .To(context)
                    .Fill <Customer>()
                    .Merge <Customer>()
                    .Merge <Customer>()
                    .ExecuteAsync();

            t.Wait();
        }
Ejemplo n.º 20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="context"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        protected override async Task VailOfRole(
            IServiceProvider serviceProvider,
            AuthorizationHandlerContext context,
            string uid)
        {
            if (context.Resource is not DefaultHttpContext httpContext)
            {
                return;
            }
            var res          = httpContext.GetEndpoint();
            var routePattern = httpContext.GetRouteData().Values;
            var module       = res.Metadata.GetMetadata <RuleModuleAttribute>();
            var method       = res.Metadata.GetMetadata <RuleMethodAttribute>();

            if (module == null && method == null)
            {
                context.Succeed(this);
                return;
            }
            UsersContext usersContext = await UsersContext.GetInfo(
                serviceProvider,
                uid);

            string area = routePattern.ContainsKey("area") ? routePattern["area"].ToStringEx() : "";

            if (await Rule.IsRule_NSpecial(
                    serviceProvider,
                    await EnterpriseContext.GetInfo(serviceProvider, ClaimsPrincipalEx.FindFirstValueEx(context.User, Macro.COOKIESLOGIN_EID)),
                    usersContext,
                    ConvertEx.ToStringEx(routePattern["controller"]),
                    area,
                    ConvertEx.ToStringEx(routePattern["action"])))
            {
                context.Succeed(this);
            }
        }
 public override MembershipUser GetUser(string email, bool userIsOnline)
 {
     try
     {
         using (EnterpriseContext _db = new EnterpriseContext())
         {
             var users = from u in _db.Users
                         where u.Email == email
                         select u;
             if (users.Count() > 0)
             {
                 User           user       = users.First();
                 MembershipUser memberUser = new MembershipUser("MyMembershipProvider", user.Email, null, null, null, null,
                                                                false, false, user.CreationDate, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);
                 return(memberUser);
             }
         }
     }
     catch
     {
         return(null);
     }
     return(null);
 }
Ejemplo n.º 22
0
        public void GetBusinessReturnsListOfBusiness()
        {
            // Arrange

            var options = new DbContextOptionsBuilder <EnterpriseContext>().UseInMemoryDatabase("Enterprise").Options;
            var context = new EnterpriseContext(options);

            context.Businesses.Add(new Business {
                Id = 2, Name = "New Business"
            });
            var controller = new BusinessController(context);

            // Act

            IActionResult actionResult   = controller.GetBuisnesses();
            var           okObjectResult = actionResult as OkObjectResult;
            var           valueresult    = okObjectResult.Value as IEnumerable <Business>;

            // Assert

            Assert.NotNull(valueresult);
            Assert.NotNull(okObjectResult);
            Assert.Equal(200, okObjectResult.StatusCode);
        }
Ejemplo n.º 23
0
 static Settings()
 {
     Context = new EnterpriseContext(new DbContextOptionsBuilder <EnterpriseContext>()
                                     .UseSqlite("Filename=desktop_games.db")
                                     .UseLazyLoadingProxies().Options);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// 递归判断用户菜单权限
        /// </summary>
        /// <param name="navBarItems"></param>
        /// <returns></returns>
        private async Task <List <NavBarItem> > IsRule(List <NavBarItem> navBarItems)
        {
            //筛选子节点
            foreach (var item in navBarItems)
            {
                if (item.Children != null)
                {
                    item.Children = await IsRule(item.Children);
                }
            }
            var newItems = navBarItems.Select(async F =>
            {
                //子项筛选之后为空则判断父级菜单自身权限
                if (F.Children != null ? (F.Children.Count > 0 ? false : true) : true)
                {
                    if (F.Module == null)
                    {
                        return new
                        {
                            Info  = F,
                            Value = true
                        }
                    }
                    ;
                    if (F.Module.Count < 1)
                    {
                        return new
                        {
                            Info  = F,
                            Value = true
                        }
                    }
                    ;
                    if (F.Module[0].Split('/').Length < 3)
                    {
                        return new
                        {
                            Info  = F,
                            Value = true
                        }
                    }
                    ;

                    //判断权限
                    return(new
                    {
                        Info = F,
                        Value = await Rule.IsRule_NSpecial(
                            HttpContext.RequestServices,
                            EnterpriseContext.EmptyContext(HttpContext.RequestServices),
                            (await UserInfoForLogin),
                            F.Module[0].Split('/')[1],
                            F.Module[0].Split('/')[0],
                            F.Module[0].Split('/')[2])
                    });
                }
                //子项筛选之后有值则默认显示父级菜单
                return(new
                {
                    Info = F,
                    Value = true
                });
            });
            var result = await Task.WhenAll(newItems);

            navBarItems = (from T in result where T.Value select T.Info).ToList();
            return(navBarItems);
        }
Ejemplo n.º 25
0
 public EmployeeRepository(EnterpriseContext db)
 {
     this.db = db;
 }
Ejemplo n.º 26
0
 public BusinessRepository(EnterpriseContext context)
 {
     _context = context;
 }
Ejemplo n.º 27
0
 public FamilyController(EnterpriseContext context)
 {
     _familyRepository = new FamilyRepository(context);
 }
Ejemplo n.º 28
0
 public OrderProductRepository(EnterpriseContext db)
 {
     this.db = db;
 }
Ejemplo n.º 29
0
 public OfferingRepository(EnterpriseContext context)
 {
     _context = context;
 }
 public CountryController(EnterpriseContext context)
 {
     _countryRepository = new CountryRepository(context);
 }