Ejemplo n.º 1
0
        public static string GetChildrenChart(int parentId, bool isMainSubset)
        {
            using (var db = new SmartStoreContext())
            {
                var parent            = db.Users.Find(parentId);
                var userProfitManager = new UserProfitManager(db);
                var userPoints        = userProfitManager.GetUserPointsAmount(parent);
                var content           = $"<li><div class='user'><img src= '/Images/User/{parent.UserImage ?? "user-avatar.png"}' class='img-responsive' />" +
                                        $"<div class='name'>{parent.UserFirstName} {parent.UserLastName}</div><div class='role'>{parent.Role.RoleTitle}</div><div class='role'>Points: {userPoints}</div>";

                if (isMainSubset)
                {
                    content += $"<button class='btn btn-sm btn-danger' onclick='btnRemoveSubset({parent.Id})'>Remove Subset</button>";
                }

                content += "</div>";
                var children = db.Users.Where(u => u.UserIdentifierCode == parent.UserCode).ToList();
                if (children.Any())
                {
                    content += "<ul>";
                    children.ToList().ForEach(child =>
                    {
                        if (child.IsActive == true)
                        {
                            content += GetChildrenChart(child.Id, false);
                        }
                    });
                    content += "</ul>";
                }
                content += "</li>";
                return(content);
            }
        }
Ejemplo n.º 2
0
 public AuthRepository()
 {
     _ctx         = new ApplicationDbContext();
     _sctx        = new SmartStoreContext();
     _nctx        = new NopCommerceContext();
     _userManager = new ApplicationUserManager(new CustomUserStore(_ctx));
     _roleManager = new ApplicationRoleManager(new CustomRoleStore(_ctx));
 }
        private static List <int> GetOperationTasks(int operationId)
        {
            var _db = new SmartStoreContext();

            return((from tr in _db.AuthorizationItemsRelations
                    join t in _db.AuthorizationItems on tr.FirstItemId equals t.Id
                    where t.ItemType == (int)AuthorizationItemTypes.Task && tr.SecondItemId == operationId
                    select t.Id).ToList());
        }
        private static List <int> GetTasksRoles(List <int> taskIds)
        {
            var _db = new SmartStoreContext();

            return((from rr in _db.AuthorizationItemsRelations
                    join r in _db.AuthorizationItems on rr.FirstItemId equals r.Id
                    where r.ItemType == (int)AuthorizationItemTypes.Role && taskIds.Contains(rr.SecondItemId)
                    select r.Id).ToList());
        }
Ejemplo n.º 5
0
        public SmartProductDtoValidator(SmartStoreContext context, SmartProductDto productDto)
        {
            RuleFor(x => x.Name)
            .NotNull()
            .NotEmpty()
            .MinimumLength(1)
            .MaximumLength(150);

            RuleFor(x => x.Description)
            .NotNull()
            .NotEmpty()
            .MaximumLength(4000);

            RuleFor(x => x.Width)
            .NotNull()
            .GreaterThanOrEqualTo(0);

            RuleFor(x => x.Height)
            .NotNull()
            .GreaterThanOrEqualTo(0);

            RuleFor(x => x.Length)
            .NotNull()
            .GreaterThanOrEqualTo(0);

            RuleFor(x => x.Weight)
            .NotNull()
            .GreaterThanOrEqualTo(0);

            RuleFor(x => x.StockQuantity)
            .NotNull()
            .GreaterThanOrEqualTo(0);

            RuleFor(x => x.IsAvailable)
            .NotNull();

            RuleFor(x => x.Price)
            .NotNull()
            .GreaterThanOrEqualTo(0);

            RuleFor(x => x.ManufacturerId)
            .NotEmpty()
            .Must(id => context.Manufacturers.Any(product => product.Id == productDto.ManufacturerId))
            .WithErrorCode($"Specified ManufacturerId: {productDto.ManufacturerId} does not exists for table Manufacturers.")
            .WithMessage("Please specify existing manufacturer.");

            RuleFor(x => x.CategoryId)
            .NotNull()
            .NotEmpty()
            .Must(id => context.Categories.Any(product => product.Id.Equals(productDto.CategoryId)))
            .WithErrorCode($"Specified CategoryId: {productDto.CategoryId} does not exists for table Category.")
            .WithMessage("Please specify existing category.");
        }
Ejemplo n.º 6
0
        public int GetGroupProductCount(int id)
        {
            var count = 0;

            using (var context = new SmartStoreContext())
            {
                count += context.Products.Where(p => p.ProductGroupId == id && (p.IsDeleted != true && p.ProductNotShow == false)).Count();
                var childrenGroupIds = context.ProductGroups.Where(p => (p.IsDeleted != true && p.GroupNotShow == false) && p.ParentId == id).Select(p => p.Id).ToList();
                foreach (var item in childrenGroupIds.ToList())
                {
                    count += GetGroupProductCount(item);
                }
            }
            return(count);
        }
Ejemplo n.º 7
0
        public void Seed(SmartStoreContext context, DbOptions dbOptions, ILogger <SmartStoreContextSeeder> logger)
        {
            if (!dbOptions.Seed)
            {
                logger.LogInformation("Seed has not been activated.");
                return;
            }

            var policy = CreatePolicy(logger, nameof(SmartStoreContextSeeder));

            policy.ExecuteAsync(async() =>
            {
                await using (context)
                {
                    await context.Database.MigrateAsync();

                    var manufacturers = GetPredefinedManufacturers();
                    if (!context.Manufacturers.Any())
                    {
                        await context.AddRangeAsync(manufacturers);
                    }

                    await context.SaveChangesAsync();

                    var categories = GetPredefinedCategories();
                    if (!context.Categories.Any())
                    {
                        await context.AddRangeAsync(categories);
                    }

                    await context.SaveChangesAsync();

                    var products = GetPredefinedProduct();
                    if (!context.Products.Any())
                    {
                        await context.AddRangeAsync(products);
                        await context.SaveChangesAsync();

                        LinkProductsWithManufacturersAndCategories(ref products, categories, manufacturers);

                        await context.SaveChangesAsync();
                    }
                }
            }).Wait();
        }
Ejemplo n.º 8
0
        public void Send(string To, string Body)
        {
            SmartStoreContext db = new SmartStoreContext();

            SmsIrRestful.Token tokenInstance = new SmsIrRestful.Token();

            string mobilenumber = To;
            string code         = Body;


            var token = tokenInstance.GetToken("a151711852a2c88060d564d5", "09378971585");

            //SmsIrRestful.UltraFast ultraFast = new SmsIrRestful.UltraFast();

            //var uf = ultraFast.Send(token, new SmsIrRestful.UltraFastSend()
            //{
            //    Mobile = Convert.ToInt64(mobilenumber),
            //    TemplateId = 5731,

            //    ParameterArray = new List<SmsIrRestful.UltraFastParameters>()
            //    {
            //        new SmsIrRestful.UltraFastParameters()
            //        {
            //            Parameter = "ثبت نام شما با موفقیت انجام شد کد فعال سازی شما" ,
            //            ParameterValue = code
            //        }
            //    }.ToArray()
            //});


            SmsIrRestful.VerificationCode verificationCode = new SmsIrRestful.VerificationCode();

            var vc = verificationCode.Send(token, new SmsIrRestful.RestVerificationCode()
            {
                MobileNumber = mobilenumber,
                Code         = code
            });
        }
        private static List <int> GetOperationRelations(int operationId)
        {
            var result = new List <int>();

            var tasks = GetOperationTasks(operationId);

            result.AddRange(tasks);

            var roles = GetTasksRoles(tasks); //indirect

            result.AddRange(roles);

            var _db     = new SmartStoreContext();
            var opRoles = (from rr in _db.AuthorizationItemsRelations
                           join r in _db.AuthorizationItems on rr.FirstItemId equals r.Id
                           where r.ItemType == (int)AuthorizationItemTypes.Role && rr.SecondItemId == operationId
                           select r.Id).ToList();

            result.AddRange(opRoles);


            return(result);
        }
Ejemplo n.º 10
0
        public static bool HasAccess(string operationTitle)
        {
            //return true;
            var _db          = new SmartStoreContext();
            var userName     = HttpContext.Current.Session["UserName"].ToString();
            var allOperation = new List <string>();

            var operation = _db.AuthorizationItems.Where(w => w.Title.ToLower() == operationTitle.ToLower() &&
                                                         w.ItemType == (int)AuthorizationItemTypes.Operation).FirstOrDefault();

            if (operation == null)
            {
                throw new Exception("Operation not found");
            }

            var operationRelations = GetOperationRelations(operation.Id);

            var userHasAccess = _db.UserAuthorizations
                                .Where(w => (operationRelations.Contains(w.AuthorizationId) || w.AuthorizationId == operation.Id) &&
                                       w.UserName == userName)
                                .Any();

            return(userHasAccess);
        }
Ejemplo n.º 11
0
 public StoreProductsCommandHandler(SmartStoreContext context, IMapper mapper, ILogger <StoreProductsCommandHandler> logger)
 {
     _context = context;
     _mapper  = mapper;
     _logger  = logger;
 }
Ejemplo n.º 12
0
 public StoreManufacturerCommandHandler(SmartStoreContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public SystemParameterRepository()
 {
     db = SmartStoreContext.GetInstance();
 }
Ejemplo n.º 14
0
 public UserProfitManager(SmartStoreContext db)
 {
     this.db = db;
 }
Ejemplo n.º 15
0
 public UserProfitManager()
 {
     this.db = new SmartStoreContext();
 }
Ejemplo n.º 16
0
 public GetProductQueryHandler(SmartStoreContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
 public GetCategoriesQueryHandler(SmartStoreContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
Ejemplo n.º 18
0
 public StoreCategoryCommandHandler(SmartStoreContext context)
 {
     _context = context;
 }