public static async Task GenerateDiscountCodes(int ammount)
        {
            List <DiscountCard> discountCards = new List <DiscountCard>();

            while (ammount > 0)
            {
                for (int i = 0; i < ammount; i++)
                {
                    string code         = RandomTextGenerator.Generate(8);
                    var    discountCard = new DiscountCard()
                    {
                        DiscountCode = code
                    };
                    discountCards.Add(discountCard);
                }

                discountCards = RemoveCommonCodeFetcher(discountCards);
                ammount      -= discountCards.Count;
            }

            var convertedDiscountCards = DiscountCardToDto(discountCards);

            AccessContext ac = new AccessContext();
            await ac.InsertMultipleCodes(convertedDiscountCards);
        }
예제 #2
0
 public ContextualStream()
     : base(AccessContext.Create(
                CsScopeLogic.Default,
                CsScopeLogic.CompleteScope),
            factory)
 {
     state = new streamData();
 }
예제 #3
0
 public UserController(AccessContext context, SignInManager <IdentityUser> singnManager, UserManager <IdentityUser> userManager, IOptions <AppSettings> appSettings)
 {
     _singnManager   = singnManager;
     _userManager    = userManager;
     _context        = context;
     _userRepository = new UserRepository(_context);
     _appSettings    = appSettings.Value;
 }
예제 #4
0
 public asyncBox(T initial)
     : base(AccessContext.Create(
                RWScopeLogic.Instance,
                RWScopeLogic.MaximumScope),
            childFactory)
 {
     state = new[] { initial };
 }
예제 #5
0
 public MyComponent(string connectionName)
     : base(AccessContext.Create(
                new FlagBasedAccessScopeLogic(),
                FlagBasedAccessScopeLogic.FullScope),
            factory.Default)
 {
     connection = message => Console.WriteLine(
         connectionName + ": " + message);
 }
        /// <summary>
        /// 校验接口访问权限。
        /// </summary>
        /// <param name="accessContext">接口访问请求上下文。</param>
        void VerifyAccessRights(AccessContext accessContext)
        {
            string interfaceName = accessContext.ActionContext.GetApiName();

            var verifyResult = apiAccessor.VerifyAccessRights(
                accessContext.Request.appId,
                interfaceName);

            if (!verifyResult.Successed)
            {
                Error.ThrowNoAccessRightException(verifyResult.Message, verifyResult.Code);
            }
        }
        /// <summary>
        /// 校验接口访问频率是否超过配置值。
        /// </summary>
        /// <param name="accessContext">接口访问请求上下文。</param>
        void VerifyAccessFrequency(AccessContext accessContext)
        {
            string interfaceName = accessContext.ActionContext.GetApiName();

            var verifyResult = apiAccessor.VerifyAccessFrequency(
                accessContext.Request.appId,
                interfaceName);

            if (verifyResult.Successed)
            {
                Error.ThrowAccessFrequencyException();
            }
        }
        /// <summary>
        /// 校验请求参数签名是否合法。
        /// </summary>
        /// <param name="accessContext">接口访问请求上下文。</param>
        void VerifyAccessSign(AccessContext accessContext)
        {
            var verifyResult = apiAccessor.VerifyAccessSign(
                accessContext.Request.appId,
                accessContext.Request.random,
                accessContext.Request.timestamp,
                accessContext.Request.sign,
                accessContext.SignaturePlainText);

            if (!verifyResult.Successed)
            {
                Error.ThrowInvalidSignException(verifyResult.Message, verifyResult.Code);
            }
        }
예제 #9
0
        public static void RecordStepIn(
            this ICyclicAccessRecord <AccessTrace> record,
            AccessContext context,
            object sender,
            string propertyName
            )
        {
            var trace = new AccessTrace()
            {
                Context = context, Sender = sender, PropertyName = propertyName
            };

            record.RecordStepIn(trace);
        }
예제 #10
0
        public static void StepInOrThrow(
            this ICyclicAccessGuard <AccessTrace> guard,
            AccessContext context,
            object sender,
            string propertyName
            )
        {
            var trace = new AccessTrace()
            {
                Context = context, Sender = sender, PropertyName = propertyName
            };

            guard.StepInOrThrow(trace);
        }
예제 #11
0
        public static bool TryStepIn(
            this ICyclicAccessGuard <AccessTrace> guard,
            AccessContext context,
            object sender,
            string propertyName
            )
        {
            var trace = new AccessTrace()
            {
                Context = context, Sender = sender, PropertyName = propertyName
            };

            return(guard.TryStepIn(trace));
        }
예제 #12
0
        public override AccessNode VisitAccess([NotNull] AccessContext context)
        {
            var name = context.Name()?.GetText();
            var expr = this.VisitFirstChild <ExprNode, Node>(new ParserRuleContext[] {
                context.invokeFunction(),
                context.instantiateObject(),
                context.expr(),
            });

            // No need to check for right parenthesis because of parser rules enforcing matching parens
            var hasParens = context.LeftParen() != null;

            var chain = context.accessChain().Invoke(VisitAccessChain);

            return(new AccessNode(name, expr, chain, hasParens, GetLocation(context)));
        }
예제 #13
0
        static int CreateForm(Form form)
        {
            // TODO: We need to change these to a selenium method when possible.
            CatfishDbContext db = new CatfishDbContext();

            Catfish.Core.Contexts.AccessContext current = new AccessContext(AccessContext.PublicAccessGuid, true, db);
            AccessContext.current = current;

            SubmissionService formSrv = new SubmissionService(db);

            form.Serialize();

            int result = formSrv.SaveForm(form);

            db.SaveChanges();

            return(result);
        }
        /// <summary>
        /// 在调用操作方法之前发生。
        /// </summary>
        /// <param name="actionContext">操作上下文。</param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            // log the request message.
            actionContext.BuildRequestLog();

            var  attr        = actionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>();
            bool isAnonymous = attr.Any(a => a is AllowAnonymousAttribute);

            if (isAnonymous)
            {
                base.OnActionExecuting(actionContext);
                return;
            }

            var accessContext = new AccessContext(actionContext);

            // 校验接口请求参数签名。
            if (AccessSignEnaled)
            {
                VerifyAccessSign(accessContext);
            }

            // 校验接口访问权限。
            if (AccessRightsEnabled)
            {
                VerifyAccessRights(accessContext);
            }

            // 判断接口访问频率是否超过配置值。
            if (AccessFrequencyEnaled)
            {
                VerifyAccessFrequency(accessContext);
            }

            base.OnActionExecuting(actionContext);
        }
예제 #15
0
 public ComponentRepository(AccessContext p_accessContext)
 {
     accessContext = p_accessContext;
 }
예제 #16
0
 public AddNewClosure(AccessContext parentContext)  : base(parentContext)
 { }
 /// <summary>
 ///  Common Filter 
 /// </summary>
 /// <param name="searchKeys"></param>
 /// <returns></returns>
 public async Task<List<Guid>> FilterUsers(FilterOptionModel filter, AccessContext Context)
 {
     var ids = await CommonSearch(filter, Context).Select(u => u.Id).ToListAsync();
     return ids.Select(i => new Guid(i)).ToList();
 }
예제 #18
0
 public AdminRepository(AccessContext p_accessContext)
 {
     accessContext = p_accessContext;
 }
        private IQueryable<ApplicationUser> CommonSearch(FilterOptionModel filter, AccessContext Context, bool onlyUsers = false)
        {
            IQueryable<ApplicationUser> users = identityContex.Users.Include(i => i.Roles).Include(u => u.Claims);


            identityContex.Users.Add(new ApplicationUser()
            {
                Id=Guid.NewGuid().ToString(),
                UserName="******",
                Email ="TestEmail"
            });

            if (!string.IsNullOrEmpty(filter.role))
            {

                var roleId = identityContex.Roles.FirstOrDefault(r => r.Name == filter.role).Id;
                users = (from user in identityContex.Users
                         join roles in identityContex.UserRoles.Where(r => r.RoleId == roleId) on user.Id equals roles.UserId
                         select user);
            }
            //To Exclude any types of admin
            // los usuarios que no tienen rol asignado es para el cliente final que hace reservas.
            if (string.IsNullOrEmpty(filter.role) && onlyUsers)
            {
                users = (from user in users
                         join userRole in identityContex.UserRoles on user.Id equals userRole.UserId
                         into gu
                         from defaultUserRole in gu.DefaultIfEmpty()
                         where defaultUserRole == null
                         select user);
            }

            if (filter.centerid.HasValue && filter.centerid != 0)
            {
                var idsToFilter =
                  // TODO verificar si el rendimiento es impactado al hacer QUerys separadaas.
                  (Context.AccountAccess.Where(al => al.CenterId == filter.centerid)
                                 .Select(c => c.UserId.ToString()).ToList());
                if (onlyUsers)
                {
                    if (idsToFilter.Any()) users = users.Where(u => idsToFilter.Contains(u.Id));
                }

                else
                {
                    users = users.Where(u =>
                         idsToFilter.Contains(u.Id) ||
                         (u.CenterId.HasValue && u.CenterId == filter.centerid.Value));
                }

            }
            filter.SearchKeys.ForEach(key =>
                         users = users.Where(u => u.UserName.ToLower().Contains(key)
                                             || u.ADDRESS.ToLower().Contains(key)
                                             || u.FirstName.ToLower().Contains(key)
                                             || u.LastName.ToLower().Contains(key)
                                             || u.DUI.ToLower().Contains(key)
                                             || u.Email.ToLower().Contains(key)));

            return users;
        }
예제 #20
0
 public ServiceRepository(AccessContext context)
 {
     this._context = context;
 }
예제 #21
0
        public async Task <ActionResult <User> > Login([FromBody] LoginUser loginUser, [FromServices] AccessContext context)
        {
            var result = await _singnManager.PasswordSignInAsync(loginUser.Login.Trim(), loginUser.Password.Trim(), false, true);


            if (result.Succeeded)
            {
                string token = await GetToken(loginUser.Login);

                var jwt = new TokenResponse(token);

                return(Ok(jwt));
            }

            return(BadRequest());
        }
        public async Task<List<ApplicationUser>> GetUsersAsync(FilterOptionModel filter, AccessContext Context, bool onlyUsers = false)
        {

            IQueryable<ApplicationUser> users = CommonSearch(filter, Context, onlyUsers);


            var accounts = await users.Include(u => u.Claims).OrderBy(u => u.UserName).Skip(filter.Skip).Take(filter.Limit).ToListAsync();

            //refresh profile pictures from extenal login

            foreach (var account in accounts.Where(a => a.Claims.Any()))
            {
                var claim = account.Claims.FirstOrDefault(c => c.ClaimType == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");

                if (claim != null)
                {
                    account.ProfilePicture = TokenExtensions.FaceBookProfilePictureFormat(claim.ClaimValue);
                }

                var claimName = account.Claims.FirstOrDefault(c => c.ClaimType == ClaimTypes.Name);
                var givenName = account.Claims.FirstOrDefault(c => c.ClaimType == ClaimTypes.GivenName);
                var phone = account.Claims.FirstOrDefault(c => c.ClaimType == ClaimTypes.MobilePhone);
                if (claimName != null && string.IsNullOrEmpty(account.FirstName)) account.FirstName = claimName.ClaimValue;
                if (givenName != null && string.IsNullOrEmpty(account.LastName)) account.LastName = givenName.ClaimValue;
                if (phone != null && string.IsNullOrEmpty(account.PhoneNumber)) account.PhoneNumber = phone.ClaimValue;

                await identityContex.SaveChangesAsync();
            }

            return accounts;
        }
 public IdentityManagerService(AccessContext context)
 {
     Context = context;
 }
예제 #24
0
 public void OnUnload(IDataHost parent)
 {
     parent.Local.Remove(Context);
     Context = null;
 }
 /// <summary>
 /// Pagination For Grids
 /// </summary>
 /// <param name="filter"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public  async Task<int> GetPageLimit(FilterOptionModel filter, AccessContext context)
 {
     return (await CommonSearch(filter, context).CountAsync()) / filter.Limit + 1;
 }
예제 #26
0
 public MarksRepository(AccessContext p_accessContext)
 {
     accessContext = p_accessContext;
 }
예제 #27
0
 public RelationController(AccessContext context)
 {
     _context = context;
 }
예제 #28
0
 public PermissionRepository(AccessContext context, ICacheService cacheService, IOptions <DataAccessOptions> options)
     : base(context, cacheService, options.Value.PermissionTtlMinutes)
 {
 }
 public InventoryController(AccessContext context)
 {
     _context = context;
 }
        public static async Task <bool> UseCodeRequest(string Code)
        {
            AccessContext ac = new AccessContext();

            return(await ac.UseCode(Code));
        }
예제 #31
0
 public LockRepository(AccessContext context, ICacheService cacheService, IOptions <DataAccessOptions> options)
     : base(context, cacheService, options.Value.LockTtlMinutes)
 {
 }
예제 #32
0
 /// <summary>
 /// Access controller constructor
 /// </summary>
 /// <param name="accessContext">Access context</param>
 public AccessController(AccessContext accessContext)
 {
     _accessContext = accessContext;
 }
예제 #33
0
 public static Closure Create(AccessContext parentContext, InsertHandler action, int index, AccessContextItem item)
 {
     return new InsertClosure(parentContext, action, index, item);
 }
        public static async Task<bool> UpdateUserAccountLevel(this Booking booking, AccessContext Context, bool ignoreStatus = false)
        {
            if ( (booking.Status == BookingStatus.Reservada|| booking.Status == BookingStatus.Pendiente) || ignoreStatus)
            {
                var center = await Context.Centers.Where(c => c.Fields.Any(f => f.Id == booking.Idcancha))
                                                .FirstOrDefaultAsync();

                if (!await Context.AccountAccess.AnyAsync(c => c.UserId == booking.Userid.ToString()))
                {
                    Context.AccountAccess.Add(new AccountAccessLevel()
                    {
                        UserId = booking.Userid.ToString(),
                        Center = center,
                    });
                    await Context.SaveChangesAsync();
                }
                return true;
            }
            return false;
        }
예제 #35
0
 public static Closure Create(AccessContext parentContext, RemoveHandler action, AccessContextItem item)
 {
     return new RemoveClosure(parentContext, action, item);
 }
예제 #36
0
 public InsertClosure(AccessContext parentContext, InsertHandler action, int index, AccessContextItem item) : base(parentContext)
 {
     _execute = action;
     _arg0 = index;
     _arg1 = item;
 }
예제 #37
0
 public static Closure Create(AccessContext parentContext, SetValueHandler action,string propertyName, object propertyValue)
 {
     return new ChangeClosure(parentContext, action, propertyName, propertyValue);
 }
예제 #38
0
 internal RemoveClosure(AccessContext parentContext, RemoveHandler action, AccessContextItem item) : base(parentContext)
 {
     _execute = action;
     _arg0 = item;
 }
예제 #39
0
 public void OnConnect(IDataHost parent, string tableName)
 {
     Context = parent.Local.Add(Guid.NewGuid().ToString());
     dataGridView1.DataSource = Context[tableName];
 }
예제 #40
0
 internal ChangeClosure(AccessContext parentContext, SetValueHandler action, string propertyName, object propertyValue) : base(parentContext)
 {
     _execute = action;
     _arg0 = propertyName;
     _arg1 = propertyValue;
 }
예제 #41
0
 public void OnUnload(IDataHost parent)
 {
     parent.Local.Remove(Context);
     Context = null;
 }
예제 #42
0
 /// <summary>
 /// Creates an instance of the class
 /// </summary>
 /// <param name="parentContext">associated context</param>
 public Closure(AccessContext parentContext)
 {
     ParentContext = parentContext;
 }
예제 #43
0
 public ServiceController(AccessContext context)
 {
     _serviceRepository = new ServiceRepository(context);
 }
예제 #44
0
 public static Closure Create(AccessContext parentContext, AddNewHandler action)
 {
     return new AddNewClosure(parentContext) { _execute = () => action() };
 }
예제 #45
0
 public ProductRepository(AccessContext p_accessContext)
 {
     accessContext = p_accessContext;
 }
 public Task<List<ApplicationUser>> GetAllUserNames(AccessContext context)
 {
     return CommonSearch(new FilterOptionModel()).Select(u => new ApplicationUser()
     {
         UserName = u.UserName,
         Id = u.Id
     }).ToListAsync();
 }
예제 #47
0
        public async Task <ActionResult <User> > Post([FromBody] CreateUser createUser, [FromServices] AccessContext context)
        {
            User user = new User
            {
                Name      = createUser.Name,
                LastName  = createUser.LastName,
                BirthDate = createUser.BirthDate
            };

            var response = await context.User.AddAsync(user);


            var identityUser = new IdentityUser
            {
                Id             = user.Id,
                UserName       = createUser.Email.Trim(),
                Email          = createUser.Email.Trim(),
                EmailConfirmed = true,
            };


            var result = await _userManager.CreateAsync(identityUser, createUser.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            await context.SaveChangesAsync();


            string token = await GetToken(createUser.Email);

            var jwt = new TokenResponse(token);


            return(Ok(jwt));
        }
        /// <summary>
        /// User Schedules Summary
        /// </summary>
        /// <param name="context"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<UserInfo> GetUserSummaryAsync(AccessContext context, string id)
        {
            var user = await GetUserAsync(id.ToString());

            IQueryable<Booking> query = context.Bookings.Where(b => b.Userid == id);

            var centerid = await Context.GetCenterIdAsync();// ClaimsPrincipal.Current.CenterId();

            if (centerid.HasValue) query = query.Where(b => b.Field.CenterId == centerid.Value);

            var data = await query.GroupBy(b => b.Status)
                       .Select(g => new
                       {
                           Label = g.Key.ToString(),
                           Count = g.Count(),
                       }).ToListAsync();


            var inf = new UserInfo()
            {
                Email = user.Email,
                Id = user.Id,
                Name = user.Claims.FinUserName(),
                BookingSummary = data.Select(d => new BookingSummary() { Label = d.Label, Count = d.Count }).ToList()
            };

            inf.BookingSummary.Add(new BookingSummary() { Label = "Total", Count = data.Sum(s => s.Count) });

            return inf;

        }
예제 #49
0
 public void OnConnect(IDataHost parent, string tableName)
 {
     Context = parent.Local.Add(Guid.NewGuid().ToString());
     dataGridView1.DataSource = Context[tableName];
 }