Пример #1
0
        public bool IsValid(Guid publicId, out AccountTicket ticket)
        {
            ticket = null;

            // The Result property blocks the calling thread until the task finishes.
            // Ref.: https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-return-a-value-from-a-task

            var model = _repository
                        .GetByPublicIdAsync(publicId)
                        .Result;

            if (model == null)
            {
                return(false);
            }

            ticket = new AccountTicket
            {
                Email        = model.Email,
                Id           = model.Id,
                Name         = model.Name,
                PrivateId    = model.PrivateId,
                PublicId     = model.PublicId,
                EnterpriseId = model.EnterpriseId
            };

            return(true);
        }
Пример #2
0
 public override async Task <IEnumerable <Customer> > GetAllAsync(AccountTicket user)
 {
     return(await _database.Customers
            .AsNoTracking()
            .Where(e => e.EnterpriseId == user.EnterpriseId)
            .ToListAsync());
 }
Пример #3
0
        public async Task <ModeEnum> GetAccessAreaMode(AccountTicket ticket, AreaEnum area)
        {
            var response = new ModeEnum();

            var lst = await _repository.GetAreaAccess(ticket, (int)area);

            foreach (var item in lst)
            {
                if (item.CanCreate)
                {
                    response |= ModeEnum.Create;
                }

                if (item.CanDelete)
                {
                    response |= ModeEnum.Delete;
                }

                if (item.CanModify)
                {
                    response |= ModeEnum.Modify;
                }

                if (item.CanRead)
                {
                    response |= ModeEnum.Read;
                }
            }

            return(response);
        }
Пример #4
0
        protected override bool Validate
            (AccountTicket user, GroupRequest request, Group model)
        {
            if (model.Id > 0)
            {
                if (model.EnterpriseId == null)
                {
                    State.Add("", Messages.EnterpriseId_ReadOnly);

                    return(false);
                }

                if (model.EnterpriseId != user.EnterpriseId)
                {
                    State.Add("", Messages.EnterpriseId_Invalid);

                    return(false);
                }

                if (request.EntityVersion != null &&
                    request.EntityVersion != model.LastModifiedDate)
                {
                    State.Add("EntityVersion", Messages.EntityVersion_Conflict);

                    return(false);
                }
            }

            return(base.Validate(user, request, model));
        }
Пример #5
0
        public override async Task <Group> GetAsync(AccountTicket user, int id)
        {
            var enterpriseId = user?.EnterpriseId;

            return(await _database.Groups
                   .Where(e => e.EnterpriseId == null || e.EnterpriseId == enterpriseId)
                   .FirstOrDefaultAsync(e => e.Id == id));
        }
Пример #6
0
        public override async Task <IEnumerable <Group> > GetAllAsync(AccountTicket user)
        {
            var enterpriseId = user?.EnterpriseId;

            return(await _database.Groups
                   .AsNoTracking()
                   .Where(e => e.EnterpriseId == null || e.EnterpriseId == enterpriseId)
                   .ToListAsync());
        }
Пример #7
0
        protected override Customer Parse(AccountTicket user, CustomerRequest request)
        {
            return(new Customer
            {
                Name = request.Name,
                EnterpriseId = user.EnterpriseId,

                CreationDate = DateTime.Now,
                CreationUserId = user.Id,
                LastModifiedDate = DateTime.Now,
                LastModifiedUserId = user.Id
            });
        }
Пример #8
0
        public async Task <bool> HasPolicyAccess
            (AccountTicket user, int policyId)
        {
            return(await _database.PolicyAccess
                   .AsNoTracking()
                   .Include(e => e.Group.UserGroups)

                   .Where(e => e.Group.UserGroups
                          .Any(ug => ug.UserId == user.Id)
                          )
                   .Where(e => e.PolicyId == policyId)

                   .AnyAsync());
        }
Пример #9
0
        public async Task <IEnumerable <AreaAccess> > GetAreaAccess
            (AccountTicket user, int areaId)
        {
            return(await _database.AreaAccess
                   .AsNoTracking()
                   .Include(e => e.Group.UserGroups)

                   .Where(e => e.Group.UserGroups
                          .Any(ug => ug.UserId == user.Id)
                          )
                   .Where(e => e.AreaId == areaId)

                   .ToListAsync());
        }
Пример #10
0
        public override async Task SaveAsync(AccountTicket user, Customer model)
        {
            if (model.Id > 0)
            {
                _database.Entry(model).State = EntityState.Modified;
            }
            else
            {
                await _database.Customers.AddAsync(model);
            }

            await _database.SaveChangesAsync();

            return;
        }
Пример #11
0
 public override async Task <Customer> GetAsync(AccountTicket user, int id)
 {
     return(await _database.Customers
            .Where(e => e.EnterpriseId == user.EnterpriseId)
            .FirstOrDefaultAsync(e => e.Id == id));
 }
Пример #12
0
 public async Task <bool> HasPolicyAccess(AccountTicket ticket, PolicyEnum policy)
 {
     return(await _repository.HasPolicyAccess(ticket, (int)policy));
 }
Пример #13
0
 protected override bool Validate
     (AccountTicket user, CustomerRequest request)
 {
     return(base.Validate(user, request));
 }
Пример #14
0
 protected override void AuditDelete(AccountTicket user, Customer model)
 {
     model.Inactive           = true;
     model.LastModifiedDate   = DateTime.Now;
     model.LastModifiedUserId = user.Id;
 }
Пример #15
0
 protected override void Merge(AccountTicket user, Customer model, CustomerRequest request)
 {
     model.Name               = request.Name;
     model.LastModifiedDate   = DateTime.Now;
     model.LastModifiedUserId = user.Id;
 }