Integrated with user API
Refactoring Mocks and App
This commit is contained in:
parent
ea2aa57426
commit
e9c9ccd2d3
@ -9,12 +9,19 @@ namespace eShopOnContainers.Core.Extensions
|
||||
{
|
||||
ObservableCollection<T> collection = new ObservableCollection<T>();
|
||||
|
||||
foreach (T item in source)
|
||||
try
|
||||
{
|
||||
collection.Add(item);
|
||||
}
|
||||
foreach (T item in source)
|
||||
{
|
||||
collection.Add(item);
|
||||
}
|
||||
|
||||
return collection;
|
||||
return collection;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return collection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,8 @@
|
||||
|
||||
public string IdentityEndpoint { get; set; }
|
||||
|
||||
public string UserInfoEndpoint { get; set; }
|
||||
|
||||
public string LogoutEndpoint { get; set; }
|
||||
|
||||
public string IdentityCallback { get; set; }
|
||||
@ -46,6 +48,7 @@
|
||||
OrdersEndpoint = string.Format("{0}:5102", baseEndpoint);
|
||||
BasketEndpoint = string.Format("{0}:5103", baseEndpoint);
|
||||
IdentityEndpoint = string.Format("{0}:5105/connect/authorize", baseEndpoint);
|
||||
UserInfoEndpoint = string.Format("{0}:5105/connect/userinfo", baseEndpoint);
|
||||
LogoutEndpoint = string.Format("{0}:5105/connect/endsession", baseEndpoint);
|
||||
IdentityCallback = "http://eshopxamarin/callback.html";
|
||||
}
|
||||
|
@ -1,18 +0,0 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace eShopOnContainers.Core.Helpers
|
||||
{
|
||||
public class NumericHelper
|
||||
{
|
||||
public static ObservableCollection<int> GetNumericList(int count = 100)
|
||||
{
|
||||
var result = new ObservableCollection<int>();
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
result.Add(i);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,105 +1,23 @@
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Xamarin.Forms;
|
||||
using System;
|
||||
|
||||
namespace eShopOnContainers.Core.Models.Basket
|
||||
{
|
||||
public class BasketItem : ExtendedBindableObject
|
||||
public class BasketItem
|
||||
{
|
||||
private string _id;
|
||||
private string _productId;
|
||||
private string _productName;
|
||||
private decimal _unitPrice;
|
||||
private int _quantity;
|
||||
private string _pictureUrl;
|
||||
private ObservableCollection<int> _numbers;
|
||||
public string Id { get; set; }
|
||||
|
||||
public string ProductId { get; set; }
|
||||
|
||||
public BasketItem()
|
||||
{
|
||||
Numbers = NumericHelper.GetNumericList();
|
||||
}
|
||||
public string ProductName { get; set; }
|
||||
|
||||
public string Id
|
||||
{
|
||||
get { return _id; }
|
||||
set
|
||||
{
|
||||
_id = value;
|
||||
RaisePropertyChanged(() => Id);
|
||||
}
|
||||
}
|
||||
public decimal UnitPrice { get; set; }
|
||||
|
||||
public string ProductId
|
||||
{
|
||||
get { return _productId; }
|
||||
set
|
||||
{
|
||||
_productId = value;
|
||||
RaisePropertyChanged(() => ProductId);
|
||||
}
|
||||
}
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public string ProductName
|
||||
{
|
||||
get { return _productName; }
|
||||
set
|
||||
{
|
||||
_productName = value;
|
||||
RaisePropertyChanged(() => ProductName);
|
||||
}
|
||||
}
|
||||
|
||||
public decimal UnitPrice
|
||||
{
|
||||
get { return _unitPrice; }
|
||||
set
|
||||
{
|
||||
_unitPrice = value;
|
||||
RaisePropertyChanged(() => UnitPrice);
|
||||
}
|
||||
}
|
||||
|
||||
public int Quantity
|
||||
{
|
||||
get { return _quantity; }
|
||||
set
|
||||
{
|
||||
if (_quantity != value)
|
||||
{
|
||||
_quantity = value;
|
||||
RaisePropertyChanged(() => Quantity);
|
||||
RaisePropertyChanged(() => Total);
|
||||
|
||||
MessagingCenter.Send(this, MessengerKeys.UpdateProduct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string PictureUrl
|
||||
{
|
||||
get { return _pictureUrl; }
|
||||
set
|
||||
{
|
||||
_pictureUrl = value;
|
||||
RaisePropertyChanged(() => PictureUrl);
|
||||
}
|
||||
}
|
||||
public string PictureUrl { get; set; }
|
||||
|
||||
public decimal Total { get { return Quantity * UnitPrice; } }
|
||||
|
||||
public ObservableCollection<int> Numbers
|
||||
{
|
||||
get { return _numbers; }
|
||||
set
|
||||
{
|
||||
_numbers = value;
|
||||
RaisePropertyChanged(() => Numbers);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("Product Id: {0}, Quantity: {1}", ProductId, Quantity);
|
||||
|
@ -1,109 +1,18 @@
|
||||
using eShopOnContainers.Core.Helpers;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System;
|
||||
|
||||
namespace eShopOnContainers.Core.Models.Orders
|
||||
{
|
||||
public class OrderItem : ExtendedBindableObject
|
||||
public class OrderItem
|
||||
{
|
||||
private string _pictureUrl;
|
||||
private string _productId;
|
||||
private Guid _orderId;
|
||||
private string _productName;
|
||||
private decimal _unitPrice;
|
||||
private int _quantity;
|
||||
private decimal _discount;
|
||||
private ObservableCollection<int> _numbers;
|
||||
|
||||
public OrderItem()
|
||||
{
|
||||
Numbers = NumericHelper.GetNumericList();
|
||||
}
|
||||
|
||||
public string ProductId
|
||||
{
|
||||
get { return _productId; }
|
||||
set
|
||||
{
|
||||
_productId = value;
|
||||
RaisePropertyChanged(() => ProductId);
|
||||
}
|
||||
}
|
||||
|
||||
public Guid OrderId
|
||||
{
|
||||
get { return _orderId; }
|
||||
set
|
||||
{
|
||||
_orderId = value;
|
||||
RaisePropertyChanged(() => OrderId);
|
||||
}
|
||||
}
|
||||
|
||||
public string ProductName
|
||||
{
|
||||
get { return _productName; }
|
||||
set
|
||||
{
|
||||
_productName = value;
|
||||
RaisePropertyChanged(() => ProductName);
|
||||
}
|
||||
}
|
||||
|
||||
public decimal UnitPrice
|
||||
{
|
||||
get { return _unitPrice; }
|
||||
set
|
||||
{
|
||||
_unitPrice = value;
|
||||
RaisePropertyChanged(() => UnitPrice);
|
||||
}
|
||||
}
|
||||
|
||||
public int Quantity
|
||||
{
|
||||
get { return _quantity; }
|
||||
set
|
||||
{
|
||||
_quantity = value;
|
||||
RaisePropertyChanged(() => Quantity);
|
||||
RaisePropertyChanged(() => Total);
|
||||
}
|
||||
}
|
||||
|
||||
public decimal Discount
|
||||
{
|
||||
get { return _discount; }
|
||||
set
|
||||
{
|
||||
_discount = value;
|
||||
RaisePropertyChanged(() => Discount);
|
||||
}
|
||||
}
|
||||
|
||||
public Guid ProductId { get; set; }
|
||||
public Guid OrderId { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public string ProductName { get; set; }
|
||||
public string PictureUrl { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public decimal Discount { get; set; }
|
||||
public decimal Total { get { return Quantity * UnitPrice; } }
|
||||
|
||||
public string PictureUrl
|
||||
{
|
||||
get { return _pictureUrl; }
|
||||
set
|
||||
{
|
||||
_pictureUrl = value;
|
||||
RaisePropertyChanged(() => PictureUrl);
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<int> Numbers
|
||||
{
|
||||
get { return _numbers; }
|
||||
set
|
||||
{
|
||||
_numbers = value;
|
||||
RaisePropertyChanged(() => Numbers);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("Product Id: {0}, Quantity: {1}", ProductId, Quantity);
|
||||
|
@ -3,7 +3,6 @@ using System;
|
||||
|
||||
namespace eShopOnContainers.Core.Models.User
|
||||
{
|
||||
|
||||
public class PaymentInfo
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
@ -0,0 +1,55 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace eShopOnContainers.Core.Models.User
|
||||
{
|
||||
public class UserInfo
|
||||
{
|
||||
[JsonProperty("sub")]
|
||||
public string UserId { get; set; }
|
||||
|
||||
[JsonProperty("preferred_username")]
|
||||
public string PreferredUsername { get; set; }
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("last_name")]
|
||||
public string LastName { get; set; }
|
||||
|
||||
[JsonProperty("card_number")]
|
||||
public string CardNumber { get; set; }
|
||||
|
||||
[JsonProperty("card_holder")]
|
||||
public string CardHolder { get; set; }
|
||||
|
||||
[JsonProperty("card_security_number")]
|
||||
public string CardSecurityNumber { get; set; }
|
||||
|
||||
[JsonProperty("address_city")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[JsonProperty("address_country")]
|
||||
public string Country { get; set; }
|
||||
|
||||
[JsonProperty("address_state")]
|
||||
public string State { get; set; }
|
||||
|
||||
[JsonProperty("address_street")]
|
||||
public string Street { get; set; }
|
||||
|
||||
[JsonProperty("address_zip_code")]
|
||||
public string ZipCode { get; set; }
|
||||
|
||||
[JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[JsonProperty("email_verified")]
|
||||
public bool EmailVerified { get; set; }
|
||||
|
||||
[JsonProperty("phone_number")]
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
[JsonProperty("phone_number_verified")]
|
||||
public bool PhoneNumberVerified { get; set; }
|
||||
}
|
||||
}
|
@ -12,8 +12,8 @@ namespace eShopOnContainers.Core.Services.Basket
|
||||
BuyerId = "9245fe4a-d402-451c-b9ed-9c1a04247482",
|
||||
Items = new List<BasketItem>
|
||||
{
|
||||
new BasketItem { Id = "1", PictureUrl = Device.OS != TargetPlatform.Windows ? "fake_product_01.png" : "Assets/fake_product_01.png", ProductId = "1", ProductName = ".NET Bot Blue Sweatshirt (M)", Quantity = 1, UnitPrice = 19.50M },
|
||||
new BasketItem { Id = "2", PictureUrl = Device.OS != TargetPlatform.Windows ? "fake_product_04.png" : "Assets/fake_product_04.png", ProductId = "4", ProductName = ".NET Black Cupt", Quantity = 1, UnitPrice = 17.00M }
|
||||
new BasketItem { Id = "1", PictureUrl = Device.OS != TargetPlatform.Windows ? "fake_product_01.png" : "Assets/fake_product_01.png", ProductId = Common.Common.MockCatalogItemId01.ToString(), ProductName = ".NET Bot Blue Sweatshirt (M)", Quantity = 1, UnitPrice = 19.50M },
|
||||
new BasketItem { Id = "2", PictureUrl = Device.OS != TargetPlatform.Windows ? "fake_product_04.png" : "Assets/fake_product_04.png", ProductId = Common.Common.MockCatalogItemId04.ToString(), ProductName = ".NET Black Cupt", Quantity = 1, UnitPrice = 17.00M }
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using eShopOnContainers.Core.Extensions;
|
||||
using eShopOnContainers.Core.Models.Catalog;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -23,11 +24,11 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
|
||||
private ObservableCollection<CatalogItem> MockCatalog = new ObservableCollection<CatalogItem>
|
||||
{
|
||||
new CatalogItem { Id = "1", PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_01.png" : "Assets/fake_product_01.png", Name = ".NET Bot Blue Sweatshirt (M)", Price = 19.50M, CatalogBrand = "Visual Studio", CatalogType = "T-Shirt" },
|
||||
new CatalogItem { Id = "2", PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_02.png" : "Assets/fake_product_02.png", Name = ".NET Bot Purple Sweatshirt (M)", Price = 19.50M, CatalogBrand = "Visual Studio", CatalogType = "T-Shirt" },
|
||||
new CatalogItem { Id = "3", PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_03.png" : "Assets/fake_product_03.png", Name = ".NET Bot Black Sweatshirt (M)", Price = 19.95M, CatalogBrand = "Visual Studio", CatalogType = "T-Shirt" },
|
||||
new CatalogItem { Id = "4", PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_04.png" : "Assets/fake_product_04.png", Name = ".NET Black Cupt", Price = 17.00M, CatalogBrand = "Visual Studio", CatalogType = "Mug" },
|
||||
new CatalogItem { Id = "5", PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_05.png" : "Assets/fake_product_05.png", Name = "Azure Black Sweatshirt (M)", Price = 19.50M, CatalogBrand = "Azure", CatalogType = "T-Shirt" }
|
||||
new CatalogItem { Id = Common.Common.MockCatalogItemId01.ToString(), PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_01.png" : "Assets/fake_product_01.png", Name = ".NET Bot Blue Sweatshirt (M)", Price = 19.50M, CatalogBrandId = 2, CatalogBrand = "Visual Studio", CatalogTypeId = 2, CatalogType = "T-Shirt" },
|
||||
new CatalogItem { Id = Common.Common.MockCatalogItemId02.ToString(), PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_02.png" : "Assets/fake_product_02.png", Name = ".NET Bot Purple Sweatshirt (M)", Price = 19.50M, CatalogBrandId = 2, CatalogBrand = "Visual Studio", CatalogTypeId = 2, CatalogType = "T-Shirt" },
|
||||
new CatalogItem { Id = Common.Common.MockCatalogItemId03.ToString(), PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_03.png" : "Assets/fake_product_03.png", Name = ".NET Bot Black Sweatshirt (M)", Price = 19.95M, CatalogBrandId = 2, CatalogBrand = "Visual Studio", CatalogTypeId = 2, CatalogType = "T-Shirt" },
|
||||
new CatalogItem { Id = Common.Common.MockCatalogItemId04.ToString(), PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_04.png" : "Assets/fake_product_04.png", Name = ".NET Black Cupt", Price = 17.00M, CatalogBrandId = 2, CatalogBrand = "Visual Studio", CatalogTypeId = 1, CatalogType = "Mug" },
|
||||
new CatalogItem { Id = Common.Common.MockCatalogItemId05.ToString(), PictureUri = Device.OS != TargetPlatform.Windows ? "fake_product_05.png" : "Assets/fake_product_05.png", Name = "Azure Black Sweatshirt (M)", Price = 19.50M, CatalogBrandId = 1, CatalogBrand = "Azure", CatalogTypeId = 2, CatalogType = "T-Shirt" }
|
||||
};
|
||||
|
||||
public async Task<ObservableCollection<CatalogItem>> GetCatalogAsync()
|
||||
@ -43,7 +44,7 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
|
||||
return MockCatalog
|
||||
.Where(c => c.CatalogBrandId == catalogBrandId &&
|
||||
c.CatalogTypeId == catalogTypeId)
|
||||
c.CatalogTypeId == catalogTypeId)
|
||||
.ToObservableCollection();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,10 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
CatalogRoot catalog =
|
||||
await _requestProvider.GetAsync<CatalogRoot>(uri);
|
||||
|
||||
return catalog?.Data?.ToObservableCollection();
|
||||
if (catalog?.Data != null)
|
||||
return catalog?.Data.ToObservableCollection();
|
||||
else
|
||||
return new ObservableCollection<CatalogItem>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -51,7 +54,10 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
CatalogRoot catalog =
|
||||
await _requestProvider.GetAsync<CatalogRoot>(uri);
|
||||
|
||||
return catalog?.Data?.ToObservableCollection();
|
||||
if (catalog?.Data != null)
|
||||
return catalog?.Data.ToObservableCollection();
|
||||
else
|
||||
return new ObservableCollection<CatalogItem>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -77,7 +83,10 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
IEnumerable<CatalogBrand> brands =
|
||||
await _requestProvider.GetAsync<IEnumerable<CatalogBrand>>(uri);
|
||||
|
||||
return brands?.ToObservableCollection();
|
||||
if (brands != null)
|
||||
return brands?.ToObservableCollection();
|
||||
else
|
||||
return new ObservableCollection<CatalogBrand>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -98,7 +107,10 @@ namespace eShopOnContainers.Core.Services.Catalog
|
||||
IEnumerable<CatalogType> types =
|
||||
await _requestProvider.GetAsync<IEnumerable<CatalogType>>(uri);
|
||||
|
||||
return types?.ToObservableCollection();
|
||||
if (types != null)
|
||||
return types.ToObservableCollection();
|
||||
else
|
||||
return new ObservableCollection<CatalogType>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace eShopOnContainers.Core.Services.Common
|
||||
{
|
||||
public static class Common
|
||||
{
|
||||
public static Guid MockCatalogItemId01 = new Guid("0f8fad5b-d9cb-469f-a165-708677289501");
|
||||
public static Guid MockCatalogItemId02 = new Guid("0f8fad5b-d9cb-469f-a165-708677289502");
|
||||
public static Guid MockCatalogItemId03 = new Guid("0f8fad5b-d9cb-469f-a165-708677289503");
|
||||
public static Guid MockCatalogItemId04 = new Guid("0f8fad5b-d9cb-469f-a165-708677289504");
|
||||
public static Guid MockCatalogItemId05 = new Guid("0f8fad5b-d9cb-469f-a165-708677289505");
|
||||
}
|
||||
}
|
@ -52,8 +52,8 @@ namespace eShopOnContainers.Core.Services.Order
|
||||
|
||||
private static List<OrderItem> MockOrderItems = new List<OrderItem>()
|
||||
{
|
||||
new OrderItem { OrderId = Guid.NewGuid(), ProductId = "1", Discount = 15, ProductName = ".NET Bot Blue Sweatshirt (M)", Quantity = 1, UnitPrice = 16.50M },
|
||||
new OrderItem { OrderId = Guid.NewGuid(), ProductId = "3", Discount = 0, ProductName = ".NET Bot Black Sweatshirt (M)", Quantity = 2, UnitPrice = 19.95M }
|
||||
new OrderItem { OrderId = Guid.NewGuid(), ProductId = Common.Common.MockCatalogItemId01, Discount = 15, ProductName = ".NET Bot Blue Sweatshirt (M)", Quantity = 1, UnitPrice = 16.50M },
|
||||
new OrderItem { OrderId = Guid.NewGuid(), ProductId = Common.Common.MockCatalogItemId03, Discount = 0, ProductName = ".NET Bot Black Sweatshirt (M)", Quantity = 2, UnitPrice = 19.95M }
|
||||
};
|
||||
|
||||
private static List<CardType> MockCardTypes = new List<CardType>()
|
||||
|
@ -5,7 +5,6 @@ namespace eShopOnContainers.Core.Services.User
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
Task<Address> GetAddressAsync();
|
||||
Task<PaymentInfo> GetPaymentInfoAsync();
|
||||
Task<UserInfo> GetUserInfoAsync(string authToken);
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,36 @@
|
||||
using System;
|
||||
using eShopOnContainers.Core.Models.User;
|
||||
using System.Threading.Tasks;
|
||||
using eShopOnContainers.Core.Models.Orders;
|
||||
|
||||
namespace eShopOnContainers.Core.Services.User
|
||||
{
|
||||
public class UserMockService : IUserService
|
||||
{
|
||||
private static DateTime MockExpirationDate = DateTime.Now.AddYears(5);
|
||||
|
||||
private Address MockAdress = new Address
|
||||
private UserInfo MockUserInfo = new UserInfo
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
City = "Seattle, WA",
|
||||
UserId = Guid.NewGuid().ToString(),
|
||||
Name = "Jhon",
|
||||
LastName = "Doe",
|
||||
PreferredUsername = "Jdoe",
|
||||
Email = "jdoe@eshop.com",
|
||||
EmailVerified = true,
|
||||
PhoneNumber = "202-555-0165",
|
||||
PhoneNumberVerified = true,
|
||||
Address = "Seattle, WA",
|
||||
Street = "120 E 87th Street",
|
||||
CountryCode = "98122",
|
||||
ZipCode = "98101",
|
||||
Country = "United States",
|
||||
Latitude = 40.785091,
|
||||
Longitude = -73.968285,
|
||||
State = "Seattle",
|
||||
StateCode = "WA",
|
||||
ZipCode = "98101"
|
||||
};
|
||||
|
||||
private PaymentInfo MockPaymentInfo = new PaymentInfo
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
CardHolderName = "American Express",
|
||||
CardNumber = "378282246310005",
|
||||
CardType = new CardType
|
||||
{
|
||||
Id = 3,
|
||||
Name = "MasterCard"
|
||||
},
|
||||
Expiration = MockExpirationDate.ToString(),
|
||||
ExpirationMonth = MockExpirationDate.Month,
|
||||
ExpirationYear = MockExpirationDate.Year,
|
||||
SecurityNumber = "123"
|
||||
CardHolder = "American Express",
|
||||
CardSecurityNumber = "1234"
|
||||
};
|
||||
|
||||
public async Task<Address> GetAddressAsync()
|
||||
public async Task<UserInfo> GetUserInfoAsync(string authToken)
|
||||
{
|
||||
await Task.Delay(500);
|
||||
|
||||
return MockAdress;
|
||||
}
|
||||
|
||||
public async Task<PaymentInfo> GetPaymentInfoAsync()
|
||||
{
|
||||
await Task.Delay(500);
|
||||
|
||||
return MockPaymentInfo;
|
||||
return MockUserInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using eShopOnContainers.Core.Services.RequestProvider;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using eShopOnContainers.Core.Models.User;
|
||||
|
||||
namespace eShopOnContainers.Core.Services.User
|
||||
{
|
||||
public class UserService : IUserService
|
||||
{
|
||||
private readonly IRequestProvider _requestProvider;
|
||||
|
||||
public UserService(IRequestProvider requestProvider)
|
||||
{
|
||||
_requestProvider = requestProvider;
|
||||
}
|
||||
|
||||
public async Task<UserInfo> GetUserInfoAsync(string authToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.UserInfoEndpoint);
|
||||
|
||||
string uri = builder.ToString();
|
||||
|
||||
var userInfo =
|
||||
await _requestProvider.GetAsync<UserInfo>(uri, authToken);
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new UserInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,9 +8,6 @@
|
||||
// Update Basket
|
||||
public const string UpdateBasket = "UpdateBasket";
|
||||
|
||||
// Update product basket
|
||||
public const string UpdateProduct = "UpdateProduct";
|
||||
|
||||
// Filter
|
||||
public const string Filter = "Filter";
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace eShopOnContainers.ViewModels.Base
|
||||
_unityContainer.RegisterInstance<ICatalogService>(new CatalogService(requestProvider));
|
||||
_unityContainer.RegisterInstance<IBasketService>(new BasketService(requestProvider));
|
||||
_unityContainer.RegisterInstance<IOrderService>(new OrderService(requestProvider));
|
||||
_unityContainer.RegisterInstance<IUserService>(new UserMockService());
|
||||
_unityContainer.RegisterInstance<IUserService>(new UserService(requestProvider));
|
||||
|
||||
UseMockService = false;
|
||||
}
|
||||
|
@ -63,11 +63,13 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
}
|
||||
|
||||
public ICommand CheckoutCommand => new Command(Checkout);
|
||||
|
||||
|
||||
public override Task InitializeAsync(object navigationData)
|
||||
{
|
||||
MessagingCenter.Subscribe<CatalogViewModel, List<BasketItem>>(this, MessengerKeys.UpdateBasket, (sender, arg) =>
|
||||
{
|
||||
MessagingCenter.Unsubscribe<CatalogViewModel, List<BasketItem>>(this, MessengerKeys.UpdateBasket);
|
||||
|
||||
foreach (var basketItem in arg)
|
||||
{
|
||||
BadgeCount += basketItem.Quantity;
|
||||
@ -77,16 +79,13 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
|
||||
MessagingCenter.Subscribe<CatalogViewModel, CatalogItem>(this, MessengerKeys.AddProduct, (sender, arg) =>
|
||||
{
|
||||
MessagingCenter.Unsubscribe<CatalogViewModel, CatalogItem>(this, MessengerKeys.AddProduct);
|
||||
|
||||
BadgeCount++;
|
||||
|
||||
AddCatalogItem(arg);
|
||||
});
|
||||
|
||||
MessagingCenter.Subscribe<BasketItem>(this, MessengerKeys.UpdateProduct, (sender) =>
|
||||
{
|
||||
ReCalculateTotal();
|
||||
});
|
||||
|
||||
BasketItems = new ObservableCollection<BasketItem>();
|
||||
|
||||
return base.InitializeAsync(navigationData);
|
||||
@ -135,13 +134,12 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
Total += (orderItem.Quantity * orderItem.UnitPrice);
|
||||
}
|
||||
|
||||
|
||||
var shippingAddress = await _userService.GetAddressAsync();
|
||||
var authToken = Settings.AuthAccessToken;
|
||||
var userInfo = await _userService.GetUserInfoAsync(authToken);
|
||||
|
||||
await _basketService.UpdateBasketAsync(new CustomerBasket
|
||||
{
|
||||
BuyerId = shippingAddress.Id.ToString(),
|
||||
BuyerId = userInfo.UserId,
|
||||
Items = BasketItems.ToList()
|
||||
}, authToken);
|
||||
}
|
||||
|
@ -104,10 +104,10 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
Brands = await _productsService.GetCatalogBrandAsync();
|
||||
Types = await _productsService.GetCatalogTypeAsync();
|
||||
|
||||
var shippingAddress = await _userService.GetAddressAsync();
|
||||
var authToken = Settings.AuthAccessToken;
|
||||
var userInfo = await _userService.GetUserInfoAsync(authToken);
|
||||
|
||||
var basket = await _basketService.GetBasketAsync(shippingAddress.Id.ToString(), authToken);
|
||||
var basket = await _basketService.GetBasketAsync(userInfo.UserId, authToken);
|
||||
|
||||
if (basket != null && basket.Items.Any())
|
||||
{
|
||||
|
@ -78,8 +78,23 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
|
||||
OrderItems = orderItems;
|
||||
|
||||
ShippingAddress = await _userService.GetAddressAsync();
|
||||
var paymentInfo = await _userService.GetPaymentInfoAsync();
|
||||
var authToken = Settings.AuthAccessToken;
|
||||
var userInfo = await _userService.GetUserInfoAsync(authToken);
|
||||
|
||||
ShippingAddress = new Address
|
||||
{
|
||||
Street = userInfo.Street,
|
||||
ZipCode = userInfo.ZipCode,
|
||||
State = userInfo.State,
|
||||
Country = userInfo.Country,
|
||||
};
|
||||
|
||||
var paymentInfo = new PaymentInfo
|
||||
{
|
||||
CardNumber = userInfo.CardNumber,
|
||||
CardHolderName = userInfo.CardHolder,
|
||||
SecurityNumber = userInfo.CardSecurityNumber
|
||||
};
|
||||
|
||||
Order = new Order
|
||||
{
|
||||
@ -117,7 +132,8 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
{
|
||||
orderItems.Add(new OrderItem
|
||||
{
|
||||
ProductId = basketItem.ProductId,
|
||||
// TODO:
|
||||
//ProductId = basketItem.ProductId,
|
||||
ProductName = basketItem.ProductName,
|
||||
PictureUrl = basketItem.PictureUrl,
|
||||
Quantity = basketItem.Quantity,
|
||||
|
@ -2,6 +2,7 @@
|
||||
using eShopOnContainers.Core.Models.User;
|
||||
using eShopOnContainers.Core.Services.Identity;
|
||||
using eShopOnContainers.Core.Services.OpenUrl;
|
||||
using eShopOnContainers.Core.Services.User;
|
||||
using eShopOnContainers.Core.Validations;
|
||||
using eShopOnContainers.Core.ViewModels.Base;
|
||||
using eShopOnContainers.ViewModels.Base;
|
||||
@ -20,16 +21,21 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
private ValidatableObject<string> _password;
|
||||
private bool _isMock;
|
||||
private bool _isValid;
|
||||
private bool _isLogin;
|
||||
private string _authUrl;
|
||||
|
||||
private IOpenUrlService _openUrlService;
|
||||
private IIdentityService _identityService;
|
||||
private IUserService _userService;
|
||||
|
||||
public LoginViewModel(IOpenUrlService openUrlService,
|
||||
IIdentityService identityService)
|
||||
public LoginViewModel(
|
||||
IOpenUrlService openUrlService,
|
||||
IIdentityService identityService,
|
||||
IUserService userService)
|
||||
{
|
||||
_openUrlService = openUrlService;
|
||||
_identityService = identityService;
|
||||
_userService = userService;
|
||||
|
||||
_userName = new ValidatableObject<string>();
|
||||
_password = new ValidatableObject<string>();
|
||||
@ -91,6 +97,19 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLogin
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isLogin;
|
||||
}
|
||||
set
|
||||
{
|
||||
_isLogin = value;
|
||||
RaisePropertyChanged(() => IsLogin);
|
||||
}
|
||||
}
|
||||
|
||||
public string LoginUrl
|
||||
{
|
||||
get
|
||||
@ -170,6 +189,7 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
LoginUrl = _identityService.CreateAuthorizeRequest();
|
||||
|
||||
IsValid = true;
|
||||
IsLogin = true;
|
||||
|
||||
IsBusy = false;
|
||||
}
|
||||
@ -188,7 +208,7 @@ namespace eShopOnContainers.Core.ViewModels
|
||||
{
|
||||
LoginUrl = logoutRequest;
|
||||
Settings.AuthAccessToken = string.Empty;
|
||||
IsValid = true;
|
||||
IsLogin = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,10 +156,10 @@
|
||||
Text="{Binding ShippingAddress.Street}"
|
||||
Style="{StaticResource AddressStyle}"/>
|
||||
<Label
|
||||
Text="{Binding ShippingAddress.City}"
|
||||
Text="{Binding ShippingAddress.ZipCode}"
|
||||
Style="{StaticResource AddressStyle}"/>
|
||||
<Label
|
||||
Text="{Binding ShippingAddress.CountryCode}"
|
||||
Text="{Binding ShippingAddress.State}"
|
||||
Style="{StaticResource AddressStyle}"/>
|
||||
<Label
|
||||
Text="{Binding ShippingAddress.Country}"
|
||||
|
@ -259,7 +259,7 @@
|
||||
Grid.ColumnSpan="2"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
IsVisible="{Binding IsValid}">
|
||||
IsVisible="{Binding IsLogin}">
|
||||
<WebView
|
||||
Source="{Binding LoginUrl}"
|
||||
AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
|
||||
|
@ -3,7 +3,6 @@
|
||||
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="eShopOnContainers.Core.Views.Templates.BasketItemTemplate"
|
||||
xmlns:controls="clr-namespace:eShopOnContainers.Core.Controls;assembly=eShopOnContainers.Core"
|
||||
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms">
|
||||
<ContentView.Resources>
|
||||
<ResourceDictionary>
|
||||
@ -54,12 +53,12 @@
|
||||
Value="End" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="QuantityPickerStyle"
|
||||
TargetType="{x:Type controls:BindablePicker}">
|
||||
<Style x:Key="QuantityStyle"
|
||||
TargetType="{x:Type Label}">
|
||||
<Setter Property="FontFamily"
|
||||
Value="{StaticResource MontserratRegular}" />
|
||||
<Setter Property="TextColor"
|
||||
Value="{StaticResource BlackColor}" />
|
||||
<Setter Property="BackgroundColor"
|
||||
Value="Transparent" />
|
||||
<Setter Property="HorizontalOptions"
|
||||
Value="End" />
|
||||
<Setter Property="VerticalOptions"
|
||||
@ -138,19 +137,11 @@
|
||||
Grid.Column="0"
|
||||
Text="{Binding UnitPrice, StringFormat='${0:N}'}"
|
||||
Style="{StaticResource OrderItemUnitPriceStyle}"/>
|
||||
<controls:BindablePicker
|
||||
<!-- QUANTITY -->
|
||||
<Label
|
||||
Grid.Column="1"
|
||||
ItemsSource="{Binding Numbers}"
|
||||
SelectedItem="{Binding Quantity, Mode=TwoWay}"
|
||||
Style="{StaticResource QuantityPickerStyle}">
|
||||
<controls:BindablePicker.WidthRequest>
|
||||
<OnPlatform
|
||||
x:TypeArguments="x:Double"
|
||||
Android="36"
|
||||
iOS="36"
|
||||
WinPhone="72"/>
|
||||
</controls:BindablePicker.WidthRequest>
|
||||
</controls:BindablePicker>
|
||||
Text="{Binding Quantity}"
|
||||
Style="{StaticResource QuantityStyle}"/>
|
||||
</Grid>
|
||||
<!-- TOTAL -->
|
||||
<Label
|
||||
|
@ -65,7 +65,6 @@
|
||||
<Compile Include="Extensions\ObservableExtension.cs" />
|
||||
<Compile Include="GlobalSettings.cs" />
|
||||
<Compile Include="Helpers\EasingHelper.cs" />
|
||||
<Compile Include="Helpers\NumericHelper.cs" />
|
||||
<Compile Include="Helpers\Settings.cs" />
|
||||
<Compile Include="Models\Basket\BasketItem.cs" />
|
||||
<Compile Include="Models\Catalog\CatalogBrand.cs" />
|
||||
@ -81,8 +80,10 @@
|
||||
<Compile Include="Models\User\Address.cs" />
|
||||
<Compile Include="Models\User\LogoutParameter.cs" />
|
||||
<Compile Include="Models\User\PaymentInfo.cs" />
|
||||
<Compile Include="Models\User\UserInfo.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\Catalog\CatalogService.cs" />
|
||||
<Compile Include="Services\Common\Common.cs" />
|
||||
<Compile Include="Services\Dialog\DialogService.cs" />
|
||||
<Compile Include="Services\Dialog\IDialogService.cs" />
|
||||
<Compile Include="Services\Identity\IdentityService.cs" />
|
||||
@ -103,6 +104,7 @@
|
||||
<Compile Include="Services\RequestProvider\RequestProvider.cs" />
|
||||
<Compile Include="Services\User\IUserService.cs" />
|
||||
<Compile Include="Services\User\UserMockService.cs" />
|
||||
<Compile Include="Services\User\UserService.cs" />
|
||||
<Compile Include="Triggers\BeginAnimation.cs" />
|
||||
<Compile Include="Validations\IsNotNullOrEmptyRule.cs" />
|
||||
<Compile Include="Validations\IValidationRule.cs" />
|
||||
|
@ -10,7 +10,6 @@ namespace eShopOnContainers.Droid.Activities
|
||||
Label = "eShopOnContainers",
|
||||
Icon = "@drawable/icon",
|
||||
Theme = "@style/Theme.Splash",
|
||||
MainLauncher = true,
|
||||
NoHistory = true,
|
||||
ScreenOrientation = ScreenOrientation.Portrait)]
|
||||
public class SplashActivity : AppCompatActivity
|
||||
|
Loading…
x
Reference in New Issue
Block a user