Esempio n. 1
0
        public async Task <Guid> CreateAsync(Guid userId, Product product, CancellationToken ct)
        {
            var newProduct = new Product();
            var status     = await _storage.ProductStatuses.FirstAsync(t => t.Id == product.StatusId, ct);

            var change = newProduct.CreateWithLog(userId, x =>
            {
                x.Id              = product.Id;
                x.AccountId       = product.AccountId;
                x.ParentProductId = product.ParentProductId;
                x.Type            = product.Type;
                x.StatusId        = product.StatusId;
                x.Name            = product.Name;
                x.VendorCode      = product.VendorCode;
                x.Price           = product.Price;
                x.Image           = product.Image;
                x.IsHidden        = product.IsHidden;
                x.IsDeleted       = product.IsDeleted;
                x.CreateDateTime  = DateTime.UtcNow;
                x.Status          = status;
                x.AttributeLinks  = product.AttributeLinks.Map(x.Id);
                x.CategoryLinks   = product.CategoryLinks.Map(x.Id);
            });

            var entry = await _storage.AddAsync(newProduct, ct);

            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);

            return(entry.Entity.Id);
        }
Esempio n. 2
0
        public async Task <Guid> CreateAsync(Guid userId, ProductStatus status, CancellationToken ct)
        {
            var newStatus = new ProductStatus();
            var change    = newStatus.CreateWithLog(userId, x =>
            {
                x.Id             = status.Id;
                x.AccountId      = status.AccountId;
                x.Name           = status.Name;
                x.IsDeleted      = status.IsDeleted;
                x.CreateDateTime = DateTime.UtcNow;
            });

            var entry = await _storage.AddAsync(newStatus, ct);

            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);

            return(entry.Entity.Id);
        }
        public async Task <Guid> CreateAsync(Guid userId, ProductAttribute attribute, CancellationToken ct)
        {
            var newAttribute = new ProductAttribute();
            var change       = newAttribute.CreateWithLog(userId, x =>
            {
                x.Id             = attribute.Id;
                x.AccountId      = attribute.AccountId;
                x.Type           = attribute.Type;
                x.Key            = attribute.Key;
                x.IsDeleted      = attribute.IsDeleted;
                x.CreateDateTime = DateTime.UtcNow;
            });

            var entry = await _storage.AddAsync(newAttribute, ct);

            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);

            return(entry.Entity.Id);
        }