Ejemplo n.º 1
0
 private void PrepareWithToken <TEntity, TDto, T>(ConcurrencyToken <TEntity> entity, TDto dto, EntityState state)
     where TDto : EntityDto <T> where T : IEquatable <T>
 {
     dto.ConcurrencyToken = entity.Token;
     this.Entry(dto).Property(x => x.ConcurrencyToken).CurrentValue  = Guid.NewGuid().ToString("D");
     this.Entry(dto).Property(x => x.ConcurrencyToken).OriginalValue = entity.Token;
     this.Entry(dto).State = state;
 }
Ejemplo n.º 2
0
 public ProductModel(ConcurrencyToken <Product> product)
 {
     Id      = product.Entity.Id.Value;
     Version = product.Token;
     Title   = product.Entity.Title.Value;
     Price   = product.Entity.Price.Value;
     ImageId = product.Entity.Image.Value;
 }
Ejemplo n.º 3
0
        public async Task Update(ConcurrencyToken <Product> product)
        {
            var original = await _context.Products.SingleAsync(p => p.Id == product.Entity.Id.Value);

            original.Price = product.Entity.Price.Value;
            original.Title = product.Entity.Title.Value;
            _context.UpdateWithToken <Product, ProductDto, Guid>(product, original);
        }
Ejemplo n.º 4
0
 public ProductCategoryModel(ConcurrencyToken <ProductCategory> productCategory)
 {
     Id               = productCategory.Entity.Id.Value;
     Version          = productCategory.Token;
     Title            = productCategory.Entity.Title.Value;
     ShortDescription = productCategory.Entity.ShortDescription.Value;
     ImageId          = productCategory.Entity.Image.Value;
 }
Ejemplo n.º 5
0
        public async Task Remove(ConcurrencyToken <Id> id)
        {
            var original = await _context.ProductCategories
                           .SingleAsync(p => p.Id == id.Entity.Value);

            _context.DeleteWithToken <Id, ProductCategoryDto, Guid>(id, original);
            if (original.ImageId != null)
            {
                await _files.Remove(original.ImageId.Value, original.Id);
            }
        }
Ejemplo n.º 6
0
        public async Task <int> Update(ConcurrencyToken <ProductCategory> request)
        {
            if (request.Entity == null || string.IsNullOrWhiteSpace(request.Token))
            {
                throw new ArgumentNullException(nameof(request));
            }
            await _uow.Repository.Update(request);

            var count = await _uow.SaveAsync();

            return(count);
        }
Ejemplo n.º 7
0
        public async Task <int> Remove(ConcurrencyToken <Id> request)
        {
            if (request.Entity == default || string.IsNullOrWhiteSpace(request.Token))
            {
                throw new ArgumentNullException(nameof(request));
            }
            await _uow.Repository.Remove(request);

            var count = await _uow.SaveAsync();

            return(count);
        }
Ejemplo n.º 8
0
        public async Task Update(ConcurrencyToken <ProductCategory> productCategory)
        {
            await CheckForDoublesOrThrow(productCategory.Entity);

            var original = await _context.ProductCategories.SingleAsync(p => p.Id == productCategory.Entity.Id.Value);

            original.ShortDescription = productCategory.Entity.ShortDescription.Value;
            original.Title            = productCategory.Entity.Title.Value;

            var originalImageId = original.ImageId;

            original.ImageId = productCategory.Entity.Image.Value;
            _context.UpdateWithToken <ProductCategory, ProductCategoryDto, Guid>(productCategory, original);

            if (productCategory.Entity.Image.Value != originalImageId && originalImageId != null)
            {
                await _files.Remove(originalImageId.Value, original.Id);
            }
        }
Ejemplo n.º 9
0
 public void UpdateWithToken <TEntity, TDto, T>(ConcurrencyToken <TEntity> entity, TDto dto)
     where TDto : EntityDto <T> where T : IEquatable <T>
 {
     PrepareWithToken <TEntity, TDto, T>(entity, dto, EntityState.Modified);
 }
Ejemplo n.º 10
0
        public async Task Remove(ConcurrencyToken <Id> id)
        {
            var original = await _context.Products.SingleAsync(p => p.Id == id.Entity.Value);

            _context.DeleteWithToken <Id, ProductDto, Guid>(id, original);
        }