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; }
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; }
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); }
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; }
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); } }
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); }
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); }
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); } }
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); }
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); }