diff options
Diffstat (limited to 'src/Data/Database')
| -rw-r--r-- | src/Data/Database/Base.cs | 15 | ||||
| -rw-r--r-- | src/Data/Database/Category.cs | 30 | ||||
| -rw-r--r-- | src/Data/Database/Document.cs | 9 | ||||
| -rw-r--r-- | src/Data/Database/Order.cs | 98 | ||||
| -rw-r--r-- | src/Data/Database/Product.cs | 54 | ||||
| -rw-r--r-- | src/Data/Database/User.cs | 18 |
6 files changed, 224 insertions, 0 deletions
diff --git a/src/Data/Database/Base.cs b/src/Data/Database/Base.cs new file mode 100644 index 0000000..4084ec8 --- /dev/null +++ b/src/Data/Database/Base.cs @@ -0,0 +1,15 @@ +using System; + +namespace VSH.Data.Database; + +public class Base +{ + public Guid Id { get; set; } + public DateTime Created { get; set; } + public DateTime? Updated { get; set; } + + public void SetBaseValues() { + Id = Guid.NewGuid(); + Created = DateTime.UtcNow; + } +}
\ No newline at end of file diff --git a/src/Data/Database/Category.cs b/src/Data/Database/Category.cs new file mode 100644 index 0000000..6e0d324 --- /dev/null +++ b/src/Data/Database/Category.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using IOL.Helpers; +using VSH.Data.Enums; +using VSH.Utilities; + +namespace VSH.Data.Database; + +public class Category : Base +{ + public Category(string name = default) { + if (name.IsNullOrWhiteSpace()) + return; + Name = name; + Slug = name.Slugified(); + } + + public string Name { get; set; } + public string Slug { get; set; } + public CategoryVisibility VisibilityState { get; set; } + public ICollection<Product> Products { get; set; } + public bool Disabled => VisibilityState == CategoryVisibility.DISABLED; + public bool Deleted => VisibilityState == CategoryVisibility.DELETED; + + public void Update(Category update = default) { + Name = update?.Name ?? Name; + VisibilityState = update?.VisibilityState ?? VisibilityState; + Updated = DateTime.UtcNow; + } +}
\ No newline at end of file diff --git a/src/Data/Database/Document.cs b/src/Data/Database/Document.cs new file mode 100644 index 0000000..2ae40d6 --- /dev/null +++ b/src/Data/Database/Document.cs @@ -0,0 +1,9 @@ +using VSH.Data.Enums; + +namespace VSH.Data.Database; + +public class Document : Base +{ + public DocumentType Type { get; set; } + public string Content { get; set; } +}
\ No newline at end of file diff --git a/src/Data/Database/Order.cs b/src/Data/Database/Order.cs new file mode 100644 index 0000000..02869b2 --- /dev/null +++ b/src/Data/Database/Order.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using IOL.Helpers; +using IOL.VippsEcommerce.Models.Api; +using VSH.Data.Enums; +using VSH.Utilities; + +namespace VSH.Data.Database; + +public class Order : Base +{ + public string Comment { get; set; } + public string OrderReference { get; set; } + public OrderStatus Status { get; set; } + public OrderPaymentType PaymentType { get; set; } + public string VippsTransactionId { get; set; } + public ETransactionStatus VippsTransactionStatus { get; set; } + public EStatusEnum VippsStatus { get; set; } + public ContactInformation ContactInfo { get; set; } + public List<OrderProduct> Products { get; set; } + + public class ContactInformation + { + public string Name { get; set; } + public string PhoneNumber { get; set; } + public string EmailAddress { get; set; } + } + + public decimal Total(bool includeTax = true) { + if (!Products.Any()) + return default; + var total = Products.Sum(product => product.PriceAtTimeOfOrder * product.NumberOfItems); + if (includeTax) + return total; + var taxCut = total * 25 / 100; + return total - taxCut; + } + + public decimal Tax(bool includeTax = true) { + if (!Products.Any()) + return default; + var total = Products.Sum(product => product.PriceAtTimeOfOrder * product.NumberOfItems); + var taxCut = total * 25 / 100; + return taxCut; + } + + public string GetAdminMailContent(string hostname) => @$" +Referanse: {OrderReference} +Lenke: {hostname}/kontoret/bestillinger?order={OrderReference} +Betalingsmetode: {EnumName.ForPaymentType(PaymentType)} +Status: {EnumName.ForOrderStatus(Status)} +Navn: {ContactInfo.Name} +E-postadresse: {ContactInfo.EmailAddress} +Telefon: {ContactInfo.PhoneNumber} +{(Comment.HasValue() ? "Kommentar:" + Comment : "")} +"; + + public string GetCustomerMailContent(string hostname) => @$" +Hei {ContactInfo.Name}, tusen takk for din bestilling! +Gå til {hostname}/status/{OrderReference} for å få full oversikt over bestillinga. + +Hvis du har spørsmål angående din ordre er det bare å svare på denne mailen så svarer vi så raskt vi kan. + +Med venleg hilsen + +Øystein og Bodil +Vinjesvingen Handel AS +915 61 900 +"; +} + +public class OrderProduct +{ + public Guid Id { get; set; } + + public int NumberOfItems { get; set; } + + public decimal PriceAtTimeOfOrder { get; set; } + + public decimal Total(bool includeTax = true) { + if (NumberOfItems == default || PriceAtTimeOfOrder == default) + return default; + var total = PriceAtTimeOfOrder * NumberOfItems; + if (includeTax) + return total; + var taxCut = total * 25 / 100; + return total - taxCut; + } + + public decimal Tax(bool includeTax = true) { + if (NumberOfItems == default || PriceAtTimeOfOrder == default) + return default; + var total = PriceAtTimeOfOrder * NumberOfItems; + var taxCut = total * 25 / 100; + return taxCut; + } +}
\ No newline at end of file diff --git a/src/Data/Database/Product.cs b/src/Data/Database/Product.cs new file mode 100644 index 0000000..d8a3d8b --- /dev/null +++ b/src/Data/Database/Product.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using VSH.Data.Enums; +using VSH.Data.Miscellaneous; +using VSH.Data.Static; +using VSH.Utilities; + +namespace VSH.Data.Database; + +public class Product : Base +{ + public string Name { get; set; } + public string Description { get; set; } + public decimal Price { get; set; } + public PriceSuffix PriceSuffix { get; set; } + public ProductVisibility VisibilityState { get; set; } + public Category Category { get; set; } + public List<ProductImage> Images { get; set; } + public int Count { get; set; } + public string Slug { get; set; } + public bool ShowOnFrontpage { get; set; } + + public string ReadablePriceSuffix => EnumName.ForPriceSuffix(PriceSuffix); + + public AppPath GetPrimaryImage() { + var productImage = Images.OrderBy(c => c.Order).FirstOrDefault(); + return productImage != default ? productImage.GetPath() : AppPaths.DefaultProductImage; + } + + public string WebPath() => $"/produktar/{Category?.Slug}/{Slug}"; + + public bool IsVisible => VisibilityState == ProductVisibility.DEFAULT; + public bool IsAvailable => Count == -1 || Count >= 1; +} + +public class ProductImage +{ + public ProductImage(string fileName = default, int order = default) { + FileName = fileName; + Order = order; + } + + public int Order { get; } + public string FileName { get; } + + public AppPath GetPath() { + if (FileName == default) return AppPaths.DefaultProductImage; + return new AppPath { + WebPath = Path.Combine(AppPaths.ProductImages.WebPath, FileName), + HostPath = Path.Combine(AppPaths.ProductImages.HostPath, FileName), + }; + } +}
\ No newline at end of file diff --git a/src/Data/Database/User.cs b/src/Data/Database/User.cs new file mode 100644 index 0000000..f8b083d --- /dev/null +++ b/src/Data/Database/User.cs @@ -0,0 +1,18 @@ +using IOL.Helpers; + +namespace VSH.Data.Database; + +public class User : Base +{ + public User(string username) => Username = username; + public string Username { get; set; } + public string Password { get; set; } + + public void HashAndSetPassword(string password) { + Password = PasswordHelper.HashPassword(password); + } + + public bool VerifyPassword(string password) { + return PasswordHelper.Verify(password, Password); + } +}
\ No newline at end of file |
