Example #1
0
        public void UpdateBrand(DTO.Brand updatedBrand)
        {
            CheckHelper.ArgumentNotNull(updatedBrand, "updatedBrand");
            CheckHelper.ArgumentWithinCondition(!updatedBrand.IsNew(), "Brand is new.");
            Container.Get <IValidateService>().CheckIsValid(updatedBrand);

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can change brand.");

            var persistentService = Container.Get <IPersistentService>();
            var brand             = persistentService.GetEntityById <DataAccess.Brand>(updatedBrand.Id);

            CheckHelper.NotNull(brand, "Brand does not exist.");

            if (brand.Name != updatedBrand.Name)
            {
                var doesAnotherBrandWithTheSameNameExist =
                    persistentService
                    .GetEntitySet <DataAccess.Brand>()
                    .Any(b => b.Name == updatedBrand.Name);

                if (doesAnotherBrandWithTheSameNameExist)
                {
                    throw new BrandServiceException("Бренд с заданным названием уже существует.");
                }
            }

            brand.Name   = updatedBrand.Name;
            brand.Active = updatedBrand.Active;
            brand.UpdateTrackFields(Container);

            persistentService.SaveChanges();
        }
Example #2
0
        public DTO.Product[] GetActiveProductsByBrand(DTO.Brand brand)
        {
            CheckHelper.ArgumentNotNull(brand, "brand");
            CheckHelper.ArgumentWithinCondition(!brand.IsNew(), "!brand.IsNew()");

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");

            var persistentService = Container.Get<IPersistentService>();
            var dtoService = Container.Get<IDtoService>();

            return
                persistentService
                    .GetActiveEntities<DataAccess.Product>()
                    .Where(p => p.BrandId == brand.Id)
                    .OrderByDescending(p => p.ChangeDate)
                    .AsEnumerable()
                    .Select(p => dtoService.CreateProduct(p))
                    .ToArray();
        }
Example #3
0
        public void CreateBrand(DTO.Brand createdBrand)
        {
            CheckHelper.ArgumentNotNull(createdBrand, "createdBrand");
            CheckHelper.ArgumentWithinCondition(createdBrand.IsNew(), "Brand is not new.");
            Container.Get <IValidateService>().CheckIsValid(createdBrand);

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can create brand.");

            var persistentService = Container.Get <IPersistentService>();

            var doesAnotherBrandWithTheSameNameExist =
                persistentService
                .GetEntitySet <DataAccess.Brand>()
                .Any(b => b.Name == createdBrand.Name);

            if (doesAnotherBrandWithTheSameNameExist)
            {
                throw new BrandServiceException("Бренд с заданным названием уже существует.");
            }

            var brand =
                new DataAccess.Brand
            {
                Name   = createdBrand.Name,
                Active = createdBrand.Active
            };

            brand.UpdateTrackFields(Container);
            persistentService.Add(brand);

            persistentService.SaveChanges();

            createdBrand.Id         = brand.Id;
            createdBrand.CreateDate = brand.CreateDate;
            createdBrand.CreateUser = brand.CreatedBy.GetFullName();
            createdBrand.ChangeDate = brand.ChangeDate;
            createdBrand.ChangeUser = brand.ChangedBy.GetFullName();
        }
Example #4
0
        public DTO.Size[] GetActiveSizes(DTO.SubCategory subCategory, DTO.Brand brand)
        {
            CheckHelper.ArgumentNotNull(subCategory, "subCategory");
            CheckHelper.ArgumentWithinCondition(!subCategory.IsNew(), "!subCategory.IsNew()");

            CheckHelper.ArgumentNotNull(brand, "brand");
            CheckHelper.ArgumentWithinCondition(!brand.IsNew(), "!brand.IsNew()");

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");

            var persistentService = Container.Get <IPersistentService>();
            var dtoService        = Container.Get <IDtoService>();

            return
                (persistentService
                 .GetActiveEntities <DataAccess.Size>()
                 .Where(s => s.SubCategoryId == subCategory.Id && s.BrandId == brand.Id)
                 .OrderBy(s => s.Name)
                 .AsEnumerable()
                 .Select(s => dtoService.CreateSize(s))
                 .ToArray());
        }
Example #5
0
        public DTO.Size[] GetSizes(DTO.SubCategory subCategory, DTO.Brand brand, string filter)
        {
            CheckHelper.ArgumentNotNull(subCategory, "subCategory");
            CheckHelper.ArgumentWithinCondition(!subCategory.IsNew(), "!subCategory.IsNew()");
            CheckHelper.ArgumentNotNull(brand, "brand");
            CheckHelper.ArgumentWithinCondition(!brand.IsNew(), "!brand.IsNew()");

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserSeller, "Only seller can get all sizes.");

            var query =
                Container
                .Get <IPersistentService>()
                .GetEntitySet <DataAccess.Size>()
                .Where(s => s.SubCategoryId == subCategory.Id && s.BrandId == brand.Id)
                .AsQueryable();

            if (!string.IsNullOrWhiteSpace(filter))
            {
                query =
                    query
                    .Where(s =>
                           s.Name.Contains(filter) ||
                           s.Height.Contains(filter) ||
                           s.Weight.Contains(filter));
            }

            var dtoService = Container.Get <IDtoService>();

            return
                (query
                 .OrderBy(s => s.Id)
                 .ToArray()
                 .Select(s => dtoService.CreateSize(s, false))
                 .ToArray());
        }