Last active
September 18, 2020 13:11
-
-
Save mattbrailsford/05c3d48ee7397c2be8a46c657b805232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class OrderStatusRepository : RepositoryBase, IOrderStatusRepository | |
{ | |
private IDatabaseUnitOfWork _uow; | |
public OrderStatusRepository(IDatabaseUnitOfWork uow) | |
{ | |
_uow = uow; | |
} | |
public IEnumerable<OrderStatusState> GetAll() | |
{ | |
return DoFetchInternal(_uow, "WHERE deletedTimestamp = 0 ORDER BY sortOrder"); | |
} | |
public IEnumerable<OrderStatusState> GetByStore(Guid storeId) | |
{ | |
return DoFetchInternal(_uow, "WHERE storeId = @0 AND deletedTimestamp = 0 ORDER BY sortOrder", storeId); | |
} | |
public OrderStatusState Get(Guid id) | |
{ | |
return DoFetchInternal(_uow, "WHERE id = @0", id).SingleOrDefault(); | |
} | |
public Guid? GetIdByAlias(Guid storeId, string alias) | |
{ | |
if (storeId == Guid.Empty || string.IsNullOrWhiteSpace(alias)) | |
return null; | |
return _uow.Database.ExecuteScalar<Guid?>($"SELECT id FROM {Constants.DatabaseSchema.Tables.OrderStatus} WHERE storeId = @0 AND alias = @1 AND deletedTimestamp = 0", storeId, alias); | |
} | |
public void Save(OrderStatusState state, OrderStatusState originalState) | |
{ | |
var dto = OrderStatusFactory.BuildDto(state); | |
_uow.Database.Save(dto); | |
} | |
public void Delete(OrderStatusState state) | |
{ | |
state.MustNotBeNull(nameof(state)); | |
state.DeletedTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); | |
Save(state, state); | |
} | |
public int GetNextSortOrder(Guid storeId) | |
{ | |
return _uow.Database.ExecuteScalar<int>($"SELECT COUNT(1) FROM {Constants.DatabaseSchema.Tables.OrderStatus} WHERE storeId = @0 AND deletedTimestamp = 0", storeId); | |
} | |
protected IEnumerable<OrderStatusState> DoFetchInternal(IDatabaseUnitOfWork uow, string sql, params object[] args) | |
{ | |
return uow.Database.Fetch<OrderStatusDto>(sql, args).Select(OrderStatusFactory.BuildState).ToList(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ProductReview productReview; | |
using (var uow = _uowProvider.Create()) | |
using (var repo = _repositoryFactory.CreateProductReviewRepository(uow)) | |
{ | |
productReview = _repo.GetProductReview(storeId, id); | |
uow.Complete(); | |
} | |
return productReview; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment