Esempio n. 1
0
        public DTO.Size CreateSize(DataAccess.Size size, bool includeOnlyActive = true)
        {
            CheckHelper.ArgumentNotNull(size, "size");
            CheckHelper.ArgumentWithinCondition(!size.IsNew(), "!size.IsNew()");

            return
                (_dtoCache.Get(
                     size,
                     s =>
            {
                var result =
                    new DTO.Size
                {
                    Id = s.Id,
                    Name = s.Name,
                    Height = s.Height,
                    Weight = s.Weight,
                    Active = s.Active
                };

                CopyTrackableFields(result, s);

                return result;
            },
                     (sDto, s) =>
            {
                sDto.Brand = CreateBrand(s.Brand, includeOnlyActive);
                sDto.SubCategory = CreateSubCategory(s.SubCategory, includeOnlyActive);
            }));
        }
Esempio n. 2
0
        public void CreateSize(DTO.Size createdSize)
        {
            CheckHelper.ArgumentNotNull(createdSize, "createdSize");
            CheckHelper.ArgumentWithinCondition(createdSize.IsNew(), "Size is not new.");
            Container.Get <IValidateService>().CheckIsValid(createdSize);
            CheckHelper.ArgumentWithinCondition(!createdSize.SubCategory.IsNew(), "SubCategory of Size is new.");
            CheckHelper.ArgumentWithinCondition(!createdSize.Brand.IsNew(), "Brand of Size is new.");

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

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

            var doesAnotherSizeWithTheSameNameSubCategoryBrandExist =
                persistentService
                .GetEntitySet <DataAccess.Size>()
                .Any(s =>
                     s.Name == createdSize.Name &&
                     s.SubCategoryId == createdSize.SubCategory.Id &&
                     s.BrandId == createdSize.Brand.Id);

            if (doesAnotherSizeWithTheSameNameSubCategoryBrandExist)
            {
                throw new SizeServiceException("Размер с заданным названием уже существует для данной подкатегории и данного бренда.");
            }

            var subCategory = persistentService.GetEntityById <SubCategory>(createdSize.SubCategory.Id);

            CheckHelper.NotNull(subCategory, "SubCategory does not exist.");
            var brand = persistentService.GetEntityById <DataAccess.Brand>(createdSize.Brand.Id);

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

            var size =
                new DataAccess.Size
            {
                Name          = createdSize.Name,
                SubCategoryId = subCategory.Id,
                SubCategory   = subCategory,
                BrandId       = brand.Id,
                Brand         = brand,
                Active        = createdSize.Active,
                Weight        = createdSize.Weight,
                Height        = createdSize.Height
            };

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

            persistentService.SaveChanges();

            createdSize.Id         = size.Id;
            createdSize.CreateDate = size.CreateDate;
            createdSize.CreateUser = size.CreatedBy.GetFullName();
            createdSize.ChangeDate = size.ChangeDate;
            createdSize.ChangeUser = size.ChangedBy.GetFullName();
        }
Esempio n. 3
0
 /// <summary>
 /// Convert SizeViewModel Entity  into Size Object
 /// </summary>
 ///<param name="model">SizeViewModel</param>
 ///<param name="RegionEntity">DataAccess.Size</param>
 ///<returns>SizeViewModel</returns>
 public static SizeViewModel ToViewModel(this DataAccess.Size entity,
                                         SizeViewModel model)
 {
     model.SessionUserId = entity.CreatedUserId;
     model.Id            = entity.Id;
     model.Name          = entity.Name;
     model.ShortName     = entity.ShortName;
     model.Ordinal       = entity.Ordinal;
     model.IsActive      = entity.IsActive;
     return(model);
 }
Esempio n. 4
0
 public static void Reset()
 {
     _theChildrensPlace_Boys_0_2_Newborn     = null;
     _theChildrensPlace_Boys_0_2_0_3_Months  = null;
     _theChildrensPlace_Boys_0_2_3_6_Months  = null;
     _theChildrensPlace_Girls_0_2_Newborn    = null;
     _theChildrensPlace_Girls_0_2_0_3_Months = null;
     _theChildrensPlace_Girls_0_2_3_6_Months = null;
     _carters_Boys_0_2_3M  = null;
     _carters_Boys_0_2_6M  = null;
     _carters_Girls_0_2_3M = null;
     _carters_Girls_0_2_6M = null;
     _sizes = null;
 }
Esempio n. 5
0
        /// <summary>
        /// Convert SizeViewModel Object into Size Entity
        /// </summary>
        ///<param name="model">SizeViewModel</param>
        ///<param name="RegionEntity">DataAccess.Size</param>
        ///<returns>DataAccess.Size</returns>
        public static DataAccess.Size ToEntity(this SizeViewModel model, DataAccess.Size entity
                                               )
        {
            if (entity.Id == 0)
            {
                entity.CreatedUserId = model.SessionUserId;
            }
            else
            {
                entity.UpdatedUserId    = model.SessionUserId;
                entity.UpdatedTimestamp = DateTime.Now;
            }

            entity.Name      = model.Name;
            entity.ShortName = model.ShortName;
            entity.Ordinal   = model.Ordinal;

            return(entity);
        }