Skip to content

Commit

Permalink
Add Audit Fields Implementation and Repository Updates (#447)
Browse files Browse the repository at this point in the history
---------
Co-authored-by: support <[email protected]>
  • Loading branch information
KrzysztofPajak authored Dec 19, 2023
1 parent 83d1c82 commit 406799b
Show file tree
Hide file tree
Showing 198 changed files with 704 additions and 1,191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public AddBrandCommandHandler(
public async Task<BrandDto> Handle(AddBrandCommand request, CancellationToken cancellationToken)
{
var brand = request.Model.ToEntity();
brand.CreatedOnUtc = DateTime.UtcNow;
brand.UpdatedOnUtc = DateTime.UtcNow;
await _brandService.InsertBrand(brand);
request.Model.SeName = await brand.ValidateSeName(request.Model.SeName, brand.Name, true, _seoSettings, _slugService, _languageService);
brand.SeName = request.Model.SeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public AddCategoryCommandHandler(
public async Task<CategoryDto> Handle(AddCategoryCommand request, CancellationToken cancellationToken)
{
var category = request.Model.ToEntity();
category.CreatedOnUtc = DateTime.UtcNow;
category.UpdatedOnUtc = DateTime.UtcNow;
await _categoryService.InsertCategory(category);
request.Model.SeName = await category.ValidateSeName(request.Model.SeName,
category.Name, true, _seoSettings, _slugService, _languageService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public AddCollectionCommandHandler(
public async Task<CollectionDto> Handle(AddCollectionCommand request, CancellationToken cancellationToken)
{
var collection = request.Model.ToEntity();
collection.CreatedOnUtc = DateTime.UtcNow;
collection.UpdatedOnUtc = DateTime.UtcNow;
await _collectionService.InsertCollection(collection);
request.Model.SeName = await collection.ValidateSeName(request.Model.SeName, collection.Name, true, _seoSettings, _slugService, _languageService);
collection.SeName = request.Model.SeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public AddProductCommandHandler(
public async Task<ProductDto> Handle(AddProductCommand request, CancellationToken cancellationToken)
{
var product = request.Model.ToEntity();
product.CreatedOnUtc = DateTime.UtcNow;
product.UpdatedOnUtc = DateTime.UtcNow;
await _productService.InsertProduct(product);

request.Model.SeName = await product.ValidateSeName(request.Model.SeName, product.Name, true, _seoSettings, _slugService, _languageService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public async Task<BrandDto> Handle(UpdateBrandCommand request, CancellationToken
var brand = await _brandService.GetBrandById(request.Model.Id);
var prevPictureId = brand.PictureId;
brand = request.Model.ToEntity(brand);
brand.UpdatedOnUtc = DateTime.UtcNow;
request.Model.SeName = await brand.ValidateSeName(request.Model.SeName, brand.Name, true, _seoSettings, _slugService, _languageService);
brand.SeName = request.Model.SeName;
await _brandService.UpdateBrand(brand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public async Task<CategoryDto> Handle(UpdateCategoryCommand request, Cancellatio
var category = await _categoryService.GetCategoryById(request.Model.Id);
var prevPictureId = category.PictureId;
category = request.Model.ToEntity(category);
category.UpdatedOnUtc = DateTime.UtcNow;
request.Model.SeName = await category.ValidateSeName(request.Model.SeName, category.Name, true, _seoSettings, _slugService, _languageService);
category.SeName = request.Model.SeName;
await _categoryService.UpdateCategory(category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public async Task<CollectionDto> Handle(UpdateCollectionCommand request, Cancell
var collection = await _collectionService.GetCollectionById(request.Model.Id);
var prevPictureId = collection.PictureId;
collection = request.Model.ToEntity(collection);
collection.UpdatedOnUtc = DateTime.UtcNow;
request.Model.SeName = await collection.ValidateSeName(request.Model.SeName, collection.Name, true, _seoSettings, _slugService, _languageService);
collection.SeName = request.Model.SeName;
await _collectionService.UpdateCollection(collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public async Task<ProductDto> Handle(UpdateProductCommand request, CancellationT
var prevPublished = product.Published;

product = request.Model.ToEntity(product);
product.UpdatedOnUtc = DateTime.UtcNow;
request.Model.SeName = await product.ValidateSeName(request.Model.SeName, product.Name, true, _seoSettings, _slugService, _languageService);
product.SeName = request.Model.SeName;
//search engine name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public AddCustomerAddressCommandHandler(ICustomerService customerService)
public async Task<AddressDto> Handle(AddCustomerAddressCommand request, CancellationToken cancellationToken)
{
var address = request.Address.ToEntity();
address.CreatedOnUtc = DateTime.UtcNow;
address.Id = "";
await _customerService.InsertAddress(address, request.Customer.Id);
return address.ToModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public AddCustomerCommandHandler(
public async Task<CustomerDto> Handle(AddCustomerCommand request, CancellationToken cancellationToken)
{
var customer = request.Model.ToEntity();
customer.CreatedOnUtc = DateTime.UtcNow;
customer.LastActivityDateUtc = DateTime.UtcNow;
if (string.IsNullOrEmpty(customer.Username))
customer.Username = customer.Email;
Expand Down
2 changes: 0 additions & 2 deletions src/API/Grand.Api/DTOs/Catalog/ProductDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ public ProductDto()
public int DisplayOrderBrand { get; set; }
public int DisplayOrderCollection { get; set; }
public bool Published { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime UpdatedOnUtc { get; set; }
public int Sold { get; set; }
public Int64 Viewed { get; set; }
public int OnSale { get; set; }
Expand Down
2 changes: 0 additions & 2 deletions src/API/Grand.Api/DTOs/Common/CurrencyDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ public class CurrencyDto : BaseApiEntityModel
public string CustomFormatting { get; set; }
public bool Published { get; set; }
public int DisplayOrder { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime UpdatedOnUtc { get; set; }
}
}
8 changes: 3 additions & 5 deletions src/API/Grand.Api/DTOs/Customers/AddressDto.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Grand.Api.Models;


namespace Grand.Api.DTOs.Customers
{
public class AddressDto : BaseApiEntityModel
public class AddressDto
{
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
Expand All @@ -19,7 +19,5 @@ public class AddressDto : BaseApiEntityModel
public string FaxNumber { get; set; }
public string Note { get; set; }
public int AddressType { get; set; }
public DateTime CreatedOnUtc { get; set; }

}
}
2 changes: 0 additions & 2 deletions src/API/Grand.Api/Infrastructure/DependencyEdmModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ protected void RegisterCustomers(ODataConventionModelBuilder builder)
addAddress.Parameter<string>(nameof(AddressDto.PhoneNumber));
addAddress.Parameter<string>(nameof(AddressDto.Note));
addAddress.Parameter<int>(nameof(AddressDto.AddressType));
addAddress.Parameter<DateTimeOffset>(nameof(AddressDto.CreatedOnUtc));
addAddress.Parameter<string>(nameof(AddressDto.ZipPostalCode));
addAddress.Parameter<string>(nameof(AddressDto.StateProvinceId));
addAddress.Returns<AddressDto>();
Expand All @@ -304,7 +303,6 @@ protected void RegisterCustomers(ODataConventionModelBuilder builder)
updateAddress.Parameter<string>(nameof(AddressDto.PhoneNumber));
updateAddress.Parameter<string>(nameof(AddressDto.Note));
updateAddress.Parameter<int>(nameof(AddressDto.AddressType));
updateAddress.Parameter<DateTimeOffset>(nameof(AddressDto.CreatedOnUtc));
updateAddress.Parameter<string>(nameof(AddressDto.ZipPostalCode));
updateAddress.Parameter<string>(nameof(AddressDto.StateProvinceId));
updateAddress.Returns<AddressDto>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ public class AddressProfile : Profile, IAutoMapperProfile
public AddressProfile()
{
CreateMap<AddressDto, Address>()
.ForMember(dest => dest.Attributes, mo => mo.Ignore())
.ForMember(dest => dest.UserFields, mo => mo.Ignore());

.ForMember(dest => dest.Attributes, mo => mo.Ignore());
CreateMap<Address, AddressDto>();
}

Expand Down
3 changes: 3 additions & 0 deletions src/API/Grand.Api/Models/BaseApiEntityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ public class BaseApiEntityModel
{
[Key]
public string Id { get; set; }
public DateTime CreatedOnUtc { get; set; }
public DateTime? UpdatedOnUtc { get; set; }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public virtual async Task UpdateHighestBid(Product product, double bid, string h
{
product.HighestBid = bid;
product.HighestBidder = highestBidder;
product.UpdatedOnUtc = DateTime.UtcNow;

await _productRepository.UpdateAsync(product);

await _cacheBase.RemoveAsync(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, product.Id));
Expand All @@ -117,7 +115,6 @@ public virtual async Task<IList<Product>> GetAuctionsToEnd()
public virtual async Task UpdateAuctionEnded(Product product, bool ended, bool endDate = false)
{
product.AuctionEnded = ended;
product.UpdatedOnUtc = DateTime.UtcNow;
if (endDate)
product.AvailableEndDateTimeUtc = DateTime.UtcNow;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ public virtual async Task<Product> CopyProduct(Product product, string newName,
AvailableEndDateTimeUtc = product.AvailableEndDateTimeUtc,
DisplayOrder = product.DisplayOrder,
Published = isPublished,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
Locales = product.Locales,
CustomerGroups = product.CustomerGroups,
Stores = product.Stores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public virtual async Task UpdateProductReview(ProductReview productReview)
.Set(x => x.ReviewText, productReview.ReviewText)
.Set(x => x.ReplyText, productReview.ReplyText)
.Set(x => x.Signature, productReview.Signature)
.Set(x => x.UpdatedOnUtc, DateTime.UtcNow)
.Set(x => x.IsApproved, productReview.IsApproved)
.Set(x => x.HelpfulNoTotal, productReview.HelpfulNoTotal)
.Set(x => x.HelpfulYesTotal, productReview.HelpfulYesTotal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public virtual async Task UpdateProduct(Product product)
.Set(x => x.BasepriceUnitId, product.BasepriceUnitId)
.Set(x => x.CallForPrice, product.CallForPrice)
.Set(x => x.CatalogPrice, product.CatalogPrice)
.Set(x => x.CreatedOnUtc, product.CreatedOnUtc)
.Set(x => x.EnteredPrice, product.EnteredPrice)
.Set(x => x.CustomerGroups, product.CustomerGroups)
.Set(x => x.DeliveryDateId, product.DeliveryDateId)
Expand Down Expand Up @@ -294,11 +293,11 @@ public virtual async Task UpdateProduct(Product product)
.Set(x => x.Weight, product.Weight)
.Set(x => x.Width, product.Width)
.Set(x => x.UserFields, product.UserFields)
.Set(x => x.UpdatedOnUtc, DateTime.UtcNow);
.Set(x => x.Ticks, DateTime.UtcNow.Ticks);

await _productRepository.UpdateOneAsync(x => x.Id == product.Id, update);

if (oldProduct.AdditionalShippingCharge != product.AdditionalShippingCharge ||
if (!oldProduct.AdditionalShippingCharge.Equals(product.AdditionalShippingCharge) ||
oldProduct.IsFreeShipping != product.IsFreeShipping ||
oldProduct.IsGiftVoucher != product.IsGiftVoucher ||
oldProduct.IsShipEnabled != product.IsShipEnabled ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ public virtual async Task AddProductToRecentlyViewedList(string customerId, stri
var recentlyViewedProduct = recentlyViewedProducts.FirstOrDefault(x => x.ProductId == productId);
if (recentlyViewedProduct == null)
{
await _recentlyViewedProducts.InsertAsync(new RecentlyViewedProduct() { CustomerId = customerId, ProductId = productId, CreatedOnUtc = DateTime.UtcNow });
await _recentlyViewedProducts.InsertAsync(new RecentlyViewedProduct() { CustomerId = customerId, ProductId = productId });
}
else
{
recentlyViewedProduct.CreatedOnUtc = DateTime.UtcNow;
await _recentlyViewedProducts.UpdateAsync(recentlyViewedProduct);
}
var maxProducts = _catalogSettings.RecentlyViewedProductsNumber;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order has been cancelled",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public CancelOrderItemCommandHandler(
await _orderService.InsertOrderNote(new OrderNote {
Note = $"Order item has been canceled - {product.Name} - Qty: {request.OrderItem.OpenQty}",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order has been deleted",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,14 @@ public DeleteOrderItemCommandHandler(
await _orderService.InsertOrderNote(new OrderNote {
Note = $"Order item has been deleted - {product.Name}",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id
});

await _inventoryManageService.AdjustReserved(product, request.OrderItem.Quantity, request.OrderItem.Attributes, request.OrderItem.WarehouseId);

//delete item
request.Order.OrderItems.Remove(request.OrderItem);

await _orderService.DeleteOrderItem(request.OrderItem);


request.Order.OrderSubtotalExclTax -= request.OrderItem.PriceExclTax;
request.Order.OrderSubtotalInclTax -= request.OrderItem.PriceInclTax;
request.Order.OrderTax -= request.OrderItem.PriceInclTax - request.OrderItem.PriceExclTax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ await _orderService.InsertOrderNote(new OrderNote
{
Note = "A new order item has been added",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id
});

Expand All @@ -92,8 +91,7 @@ await _orderService.InsertOrderNote(new OrderNote
//SenderName = senderName,
//SenderEmail = senderEmail,
//Message = giftVoucherMessage,
IsRecipientNotified = false,
CreatedOnUtc = DateTime.UtcNow
IsRecipientNotified = false
};
await _giftVoucherService.InsertGiftVoucher(gc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ await _orderService.InsertOrderNote(new OrderNote
{
Note = "Order has been marked as paid",
DisplayToCustomer = false,
CreatedOnUtc = DateTime.UtcNow,
OrderId = order.Id

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MaxOrderNumberCommandHandler(IRepository<Order> orderRepository)
var max = count > 0 ? _orderRepository.Table.Max(x => x.OrderNumber) : 0;
if (!request.OrderNumber.HasValue) return max;
if (request.OrderNumber.Value <= max) return max;
await _orderRepository.InsertAsync(new Order() { OrderNumber = request.OrderNumber.Value, Deleted = true, CreatedOnUtc = DateTime.UtcNow });
await _orderRepository.InsertAsync(new Order() { OrderNumber = request.OrderNumber.Value, Deleted = true });
max = request.OrderNumber.Value;
return max;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public async Task<bool> Handle(SetOrderStatusCommand request, CancellationToken
await _orderService.InsertOrderNote(new OrderNote {
Note = $"Order status has been changed to {request.Os.ToString()}",
DisplayToCustomer = false,
OrderId = request.Order.Id,
CreatedOnUtc = DateTime.UtcNow
OrderId = request.Order.Id
});

var customer = await _customerService.GetCustomerById(request.Order.CustomerId);
Expand Down Expand Up @@ -103,7 +102,6 @@ await _messageProviderService
await _orderService.InsertOrderNote(new OrderNote {
Note = "\"Order cancelled\" by customer.",
DisplayToCustomer = true,
CreatedOnUtc = DateTime.UtcNow,
OrderId = request.Order.Id
});
}
Expand Down
Loading

0 comments on commit 406799b

Please sign in to comment.