public Order FindOrder(int id) { Order order = null; if (id > 0) { using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { EntityFramework.Order model = db.Orders.Find(id); if (model != null) { order = DTOMapper.MapOrder(model); var orderItemModels = from ol in db.OrderLines where ol.OrderId == id select ol; var orderLines = new List <OrderLine>(); foreach (var cim in orderItemModels) { var orderLine = DTOMapper.Map <OrderLine>(cim); orderLines.Add(orderLine); } order.OrderLines = orderLines.ToArray(); } } } return(order); }
public void DTOMapper_CartMap_1() { var input = new Accessors.EntityFramework.Cart { BillingCity = "Bill City", BillingPostal = "Bill Postal", BillingAddr1 = "Bill Addr1", BillingAddr2 = "Bill Addr2", ShippingCity = "Shipping City", ShippingPostal = "Shipping Postal", ShippingAddr1 = "Shipping Addr1", ShippingAddr2 = "Shipping Addr2", }; var result = DTOMapper.Map <Cart>(input); Assert.AreEqual(input.BillingCity, result.BillingAddress.City); Assert.AreEqual(input.BillingPostal, result.BillingAddress.Postal); Assert.AreEqual(input.BillingAddr1, result.BillingAddress.Addr1); Assert.AreEqual(input.BillingAddr2, result.BillingAddress.Addr2); Assert.AreEqual(input.BillingState, result.BillingAddress.State); Assert.AreEqual(input.ShippingCity, result.ShippingAddress.City); Assert.AreEqual(input.ShippingPostal, result.ShippingAddress.Postal); Assert.AreEqual(input.ShippingAddr1, result.ShippingAddress.Addr1); Assert.AreEqual(input.ShippingAddr2, result.ShippingAddress.Addr2); Assert.AreEqual(input.ShippingState, result.ShippingAddress.State); }
public Seller Save(Seller seller) { EntityFramework.Seller model = null; using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { if (seller.Id > 0) { model = db.Sellers.Find(seller.Id); if (model == null) { // this state should never happen throw new ArgumentException($"Trying to update Seller ({seller.Id}) that does not exist"); } DTOMapper.Map(seller, model); } else { model = new EntityFramework.Seller(); DTOMapper.Map(seller, model); db.Sellers.Add(model); } db.SaveChanges(); } if (model != null) { return(Find(model.Id)); } return(null); }
public WebStoreCatalog SaveCatalog(WebStoreCatalog catalog) { // Map the seller id in the ambient context to the catalog parameter if (catalog.SellerId == 0) { catalog.SellerId = Context.SellerId; } using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { EntityFramework.Catalog model = null; if (catalog.Id > 0) { model = db.Catalogs.Find(catalog.Id); // verify the db catalog belongs to the current seller and matches the catalog input seller if (model != null && (model.SellerId != catalog.SellerId || model.SellerId != Context.SellerId)) { Logger.Error("Seller Id mismatch"); throw new ArgumentException("Seller Id mismatch"); } DTOMapper.Map(catalog, model); } else { model = new EntityFramework.Catalog(); DTOMapper.Map(catalog, model); db.Catalogs.Add(model); } db.SaveChanges(); return(Find(model.Id)); } }
BackOffice.OrderDataResponse BackOffice.IBackOfficeRemittanceManager.Totals() { try { // authenticate the user as a seller if (UtilityFactory.CreateUtility <ISecurityUtility>().BackOfficeAdminAuthenticated()) { var sellerOrderData = AccessorFactory.CreateAccessor <IRemittanceAccessor>() .SalesTotal(); if (sellerOrderData != null && sellerOrderData.Length > 0) { var result = new BackOffice.OrderDataResponse(); var items = new List <BackOffice.SellerOrderData>(); foreach (var item in sellerOrderData) { var mapped = DTOMapper.Map <BackOffice.SellerOrderData>(item); var calcResult = EngineFactory.CreateEngine <IRemittanceCalculationEngine>() .CalculateFee(mapped.SellerId, mapped.OrderTotal); mapped.FeeAmount = calcResult.FeeAmount; mapped.RemittanceAmount = calcResult.RemittanceAmount; items.Add(mapped); } result.Success = true; result.SellerOrderData = items.ToArray(); return(result); } else { return(new BackOffice.OrderDataResponse() { Success = false, Message = "No orders" }); } } return(new BackOffice.OrderDataResponse() { Success = false, Message = "BackOfficeAdmin not authenticated" }); } catch (Exception ex) { Logger.Error(ex); return(new BackOffice.OrderDataResponse() { Success = false, Message = "There was a problem accessing sellers orders" }); } }
public ContactGroupDTO GetMapper(object id) { var entity = _context.ContactGroup .Include(t => t.FundVehicle) .Include(t => t.InvestorContactGroup) .ThenInclude(t => t.ContactGroupTypes) .ThenInclude(t => t.ContactList) .ThenInclude(t => t.InvestorContact) .FirstOrDefault(t => t.ContactGroupId.ToString() == id.ToString()); var result = DTOMapper.Map <ContactGroup, ContactGroupDTO>(entity); return(result); }
WebStore.WebStoreCatalogResponse WebStore.IWebStoreCatalogManager.ShowCatalog(int catalogId) { try { // Get the webstore catalog WebStore.WebStoreCatalog result = new WebStore.WebStoreCatalog(); ICatalogAccessor catalogAccessor = AccessorFactory.CreateAccessor <ICatalogAccessor>(); DTO.WebStoreCatalog accCatalog = catalogAccessor.Find(catalogId); // Get the webstore catalog products if (accCatalog != null) { DTOMapper.Map(accCatalog, result); DTO.Product[] catalogProducts = catalogAccessor.FindAllProductsForCatalog(catalogId); List <WebStore.ProductSummary> productList = new List <WebStore.ProductSummary>(); foreach (var catalogProduct in catalogProducts) { WebStore.ProductSummary product = new WebStore.ProductSummary(); DTOMapper.Map(catalogProduct, product); productList.Add(product); } result.Products = productList.ToArray(); return(new WebStore.WebStoreCatalogResponse() { Success = true, Catalog = result }); } return(new WebStore.WebStoreCatalogResponse() { Success = false, Message = "Catalog not found" }); } catch (Exception ex) { Logger.Error(ex); return(new WebStore.WebStoreCatalogResponse() { Success = false, Message = "There was a problem accessing the catalog" }); } }
public WebStoreCart GenerateCartPricing(Cart cart) { WebStoreCart result = new WebStoreCart(); // map the cart input to a webstore cart DTOMapper.Map(cart, result); // loop through all cart items, get the current price and apply to the cart item ICatalogAccessor catAccessor = AccessorFactory.CreateAccessor <ICatalogAccessor>(); foreach (WebStoreCartItem item in result.CartItems) { if (item.Quantity > 0) { // get the current unit price and update the cart item var product = catAccessor.FindProduct(item.ProductId); if (product != null) { decimal unitPrice = product.Price; decimal extendedPrice = Math.Round(unitPrice * item.Quantity, 2); // update the web store cart item.UnitPrice = unitPrice; item.ExtendedPrice = extendedPrice; // add the amount to the subtotal result.SubTotal += Math.Round(extendedPrice, 2); } else { Logger.Error("Invalid Product Id"); throw new ArgumentException("Invalid Product Id"); } } else { Logger.Error("Invalid item quantity"); throw new ArgumentException("Invalid item quantity"); } } // set the cart total to the subtotal result.Total = result.SubTotal; return(result); }
Admin.AdminCatalogResponse Admin.IAdminCatalogManager.SaveCatalog(Admin.WebStoreCatalog catalog) { try { // authenticate the user as a seller if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated()) { // map to the accessor DTO DTO.WebStoreCatalog accCatalog = new DTO.WebStoreCatalog(); DTOMapper.Map(catalog, accCatalog); accCatalog = AccessorFactory.CreateAccessor <ICatalogAccessor>().SaveCatalog(accCatalog); if (accCatalog != null) { Admin.WebStoreCatalog result = new Admin.WebStoreCatalog(); DTOMapper.Map(accCatalog, result); return(new Admin.AdminCatalogResponse() { Success = true, Catalog = result }); } return(new Admin.AdminCatalogResponse() { Success = false, Message = "Catalog not saved" }); } return(new Admin.AdminCatalogResponse() { Success = false, Message = "Seller not authenticated" }); } catch (Exception ex) { Logger.Error(ex); return(new Admin.AdminCatalogResponse() { Success = false, Message = "There was a problem saving the catalog" }); } }
Admin.AdminProductResponse Admin.IAdminCatalogManager.ShowProduct(int catalogId, int productId) { try { //authenticate the seller if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated()) { var product = AccessorFactory.CreateAccessor <ICatalogAccessor>() .FindProduct(productId); if (product != null) { if (product.CatalogId == catalogId) { Admin.Product result = new Admin.Product(); DTOMapper.Map(product, result); return(new Admin.AdminProductResponse() { Success = true, Product = result }); } } return(new Admin.AdminProductResponse() { Success = false, Message = "Product not found" }); } return(new Admin.AdminProductResponse() { Success = false, Message = "Seller not authenticated" }); } catch (Exception ex) { Logger.Error(ex); return(new Admin.AdminProductResponse() { Success = false, Message = "There was a problem accessing the product" }); } }
Admin.AdminCatalogResponse Admin.IAdminCatalogManager.ShowCatalog(int catalogId) { try { // authenticate the user as a seller if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated()) { var catalog = AccessorFactory.CreateAccessor <ICatalogAccessor>() .Find(catalogId); if (catalog != null) { if (catalog.SellerId == Context.SellerId) { Admin.WebStoreCatalog result = new Admin.WebStoreCatalog(); DTOMapper.Map(catalog, result); return(new Admin.AdminCatalogResponse() { Success = true, Catalog = result }); } } return(new Admin.AdminCatalogResponse() { Success = false, Message = "Catalog not found" }); } return(new Admin.AdminCatalogResponse() { Success = false, Message = "Seller not authenticated" }); } catch (Exception ex) { Logger.Error(ex); return(new Admin.AdminCatalogResponse() { Success = false, Message = "There was a problem accessing the catalog" }); } }
Admin.AdminProductResponse Admin.IAdminCatalogManager.SaveProduct(int catalogId, Admin.Product product) { try { // authenticate the user as a seller if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated()) { // map to the accessor DTO DTO.Product accProduct = new DTO.Product(); DTOMapper.Map(product, accProduct); accProduct = AccessorFactory.CreateAccessor <ICatalogAccessor>().SaveProduct(catalogId, accProduct); if (accProduct != null) { Admin.Product result = new Admin.Product(); DTOMapper.Map(accProduct, result); return(new Admin.AdminProductResponse() { Success = true, Product = result }); } return(new Admin.AdminProductResponse() { Success = false, Message = "Product not saved" }); } return(new Admin.AdminProductResponse() { Success = false, Message = "Seller not authenticated" }); } catch (Exception ex) { Logger.Error(ex); return(new Admin.AdminProductResponse() { Success = false, Message = "There was a problem saving the product" }); } }
public Seller Find(int id) { using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { var model = (from s in db.Sellers where s.Id == id select s) .FirstOrDefault(); if (model != null) { var seller = new Seller(); DTOMapper.Map(model, seller); return(seller); } } return(null); }
static async Task RemoveOneVinylInTime() { while (vinylSubscr != null) { System.Threading.Thread.Sleep(5000); if (vinylSubscr == null) { continue; } await srvVinyls.RemoveStockVinyl(vinylSubscr.ID, 1); var updatedVinyl = srvVinyls.GetVinyl(vinylSubscr.ID).Result; vinylTracker.Track(DTOMapper.Map(updatedVinyl)); } }
public WebStoreCatalog Find(int catalogId) { using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { var catalogExtended = (from c in db.Catalogs join s in db.Sellers on c.SellerId equals s.Id where c.Id == catalogId select new CatalogExtended { Catalog = c, SellerName = s.Name }).FirstOrDefault(); if (catalogExtended != null) { // Using a special Map method for handling the combination of Catalog and Seller fields return(DTOMapper.Map(catalogExtended)); } return(null); } }
public AdminOpenOrdersResponse GetOrdersToFulfill() { try { // authenticate the seller if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated()) { // get the unfilfilled orders for the seller var orders = AccessorFactory.CreateAccessor <SalesAcc.IOrderAccessor>().UnfulfilledOrders(); List <AdminUnfulfilledOrder> orderList = new List <AdminUnfulfilledOrder>(); foreach (var order in orders) { // map them to the contract dto and add to the list AdminUnfulfilledOrder unfulfilledOrder = new AdminUnfulfilledOrder(); DTOMapper.Map(order, unfulfilledOrder); orderList.Add(unfulfilledOrder); } return(new AdminOpenOrdersResponse() { Success = true, Orders = orderList.ToArray() }); } return(new AdminOpenOrdersResponse() { Success = false, Message = "Seller not authenticated" }); } catch (Exception ex) { Logger.Error(ex); return(new AdminOpenOrdersResponse() { Success = false, Message = "There was a problem returning the unfulfilled orders" }); } }
Admin.AdminCatalogsResponse Admin.IAdminCatalogManager.FindCatalogs() { try { // authenticate the user as a seller if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated()) { var catalogs = AccessorFactory.CreateAccessor <ICatalogAccessor>() .FindAllSellerCatalogs(); List <Admin.WebStoreCatalog> catalogList = new List <Admin.WebStoreCatalog>(); foreach (var catalog in catalogs) { Admin.WebStoreCatalog result = new Admin.WebStoreCatalog(); DTOMapper.Map(catalog, result); catalogList.Add(result); } return(new Admin.AdminCatalogsResponse() { Success = true, Catalogs = catalogList.ToArray() }); } return(new Admin.AdminCatalogsResponse() { Success = false, Message = "Seller not authenticated" }); } catch (Exception ex) { Logger.Error(ex); return(new Admin.AdminCatalogsResponse() { Success = false, Message = "There was a problem accessing this seller's catalogs" }); } }
public Product SaveProduct(int catalogId, Product product) { // map the catalog id in the ambient context to the product parameter if (product.CatalogId == 0) { product.CatalogId = catalogId; } using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { EntityFramework.Product model = null; if (product.Id > 0) { model = db.Products.Find(product.Id); if (model == null) { Logger.Error("Product Id not found"); throw new ArgumentException("Product Id not found"); } // verify the db product belongs to the current catalog and matches the product input catalog if (model != null && (model.CatalogId != product.CatalogId || model.CatalogId != catalogId)) { Logger.Error("Catalog Id mismatch"); throw new ArgumentException("Catalog Id mismatch"); } DTOMapper.Map(product, model); } else { model = new EntityFramework.Product(); DTOMapper.Map(product, model); db.Products.Add(model); } db.SaveChanges(); return(DTOMapper.Map <Product>(model)); } }
WebStore.WebStoreProductResponse WebStore.IWebStoreCatalogManager.ShowProduct(int catalogId, int productId) { try { WebStore.ProductDetail result = new WebStore.ProductDetail(); DTO.Product catProduct = AccessorFactory.CreateAccessor <ICatalogAccessor>().FindProduct(productId); if (catProduct != null) { if (catProduct.CatalogId == catalogId) { DTOMapper.Map(AccessorFactory.CreateAccessor <ICatalogAccessor>().FindProduct(productId), result); return(new WebStore.WebStoreProductResponse() { Success = true, Product = result }); } } return(new WebStore.WebStoreProductResponse() { Success = false, Message = "Product not found" }); } catch (Exception ex) { Logger.Error(ex); return(new WebStore.WebStoreProductResponse() { Success = false, Message = "There was a problem accessing the product" }); } }
public void DTOMapper_CartMap_2() { var input = new Cart { BillingAddress = new Address { City = "Bill City", Addr1 = "addr1", Addr2 = "addr2", Postal = "zip", State = "state" }, ShippingAddress = new Address { City = "Ship City", Addr1 = "addr1", Addr2 = "addr2", Postal = "zip", State = "state" } }; var result = DTOMapper.Map <Accessors.EntityFramework.Cart>(input); Assert.AreEqual(input.BillingAddress.City, result.BillingCity); Assert.AreEqual(input.BillingAddress.Addr1, result.BillingAddr1); Assert.AreEqual(input.BillingAddress.Addr2, result.BillingAddr2); Assert.AreEqual(input.BillingAddress.Postal, result.BillingPostal); Assert.AreEqual(input.BillingAddress.State, result.BillingState); Assert.AreEqual(input.ShippingAddress.City, result.ShippingCity); Assert.AreEqual(input.ShippingAddress.Addr1, result.ShippingAddr1); Assert.AreEqual(input.ShippingAddress.Addr2, result.ShippingAddr2); Assert.AreEqual(input.ShippingAddress.Postal, result.ShippingPostal); Assert.AreEqual(input.ShippingAddress.State, result.ShippingState); }
private Cart FindCart(int catalogId, Guid id) { Cart cart = null; if (id != Guid.Empty) { using (var db = eCommerce.Accessors.EntityFramework.eCommerceDbContext.Create()) { EntityFramework.Cart model = db.Carts.Find(id); // gracefully handle situation where the cart id does not exist // or there is a catalog id mismatch if (model != null && model.CatalogId == catalogId) { cart = DTOMapper.Map <Cart>(model); var cartItemModels = from ci in db.CartItems join p in db.Products on ci.ProductId equals p.Id where ci.CartId == cart.Id select new { Model = ci, Name = p.Name }; var cartItems = new List <CartItem>(); foreach (var cim in cartItemModels) { var cartitem = DTOMapper.Map <CartItem>(cim.Model); cartitem.ProductName = cim.Name; cartItems.Add(cartitem); } cart.CartItems = cartItems.ToArray(); } } } return(cart); }
public async Task <ActionResult <IEnumerable <ExtraDTO> > > GetExtras([FromQuery] Guid pId) { var extra = (await _bll.Extras.AllAsync(pId)).Select(a => _mapper.Map(a)); return(Ok(extra)); }
public WebStore.WebStoreOrderResponse SubmitOrder(int catalogId, PaymentInstrument paymentInstrument) { try { var result = new WebStore.WebStoreOrder(); // Get the shopping cart SalesAcc.ICartAccessor cartAccessor = AccessorFactory.CreateAccessor <SalesAcc.ICartAccessor>(); var storedCart = cartAccessor.ShowCart(catalogId); // make sure we have a valid cart to start if (storedCart != null) { // Calculate the cart totals and tax var fullCart = GenerateCartPricingAndTax(storedCart); // create the order records SalesAcc.IOrderAccessor orderAccessor = AccessorFactory.CreateAccessor <SalesAcc.IOrderAccessor>(); var submittedOrder = new Order(); DTOMapper.Map(fullCart, submittedOrder); // validate the order var validationEngine = EngineFactory.CreateEngine <IOrderValidationEngine>(); var validationResponse = validationEngine.ValidateOrder(submittedOrder); if (validationResponse.Success) { submittedOrder.Status = OrderStatuses.Created; var savedOrder = orderAccessor.SaveOrder(catalogId, submittedOrder); // attempt the payment authorization if amount > 0 if (savedOrder.Total > 0) { SalesAcc.IPaymentAccessor paymentAccessor = AccessorFactory.CreateAccessor <SalesAcc.IPaymentAccessor>(); var authResult = paymentAccessor.Authorize(paymentInstrument, savedOrder.Id, savedOrder.Total); if (authResult.Success) { // save the auth code for use in capture savedOrder.AuthorizationCode = authResult.AuthCode; } else // problems with the authorization { // update the order status savedOrder.Status = OrderStatuses.Failed; savedOrder = orderAccessor.SaveOrder(catalogId, savedOrder); // Return the order response DTOMapper.Map(savedOrder, result); return(new WebStore.WebStoreOrderResponse() { Success = false, Message = "There was a problem processing the payment", Order = result }); } } // update the order status savedOrder.Status = OrderStatuses.Authorized; savedOrder = orderAccessor.SaveOrder(catalogId, savedOrder); // Delete the cart once the order is successful cartAccessor.DeleteCart(catalogId); // send order submission event UtilityFactory.CreateUtility <IAsyncUtility>().SendEvent(AsyncEventTypes.OrderSubmitted, savedOrder.Id); // Return the order response DTOMapper.Map(savedOrder, result); return(new WebStore.WebStoreOrderResponse() { Success = true, Order = result }); } // order is not valid return(new WebStore.WebStoreOrderResponse() { Success = false, Message = validationResponse.Message }); } // cart not found or not valid return(new WebStore.WebStoreOrderResponse() { Success = false, Message = "Cart is not valid" }); } catch (Exception ex) { Logger.Error(ex); return(new WebStore.WebStoreOrderResponse() { Success = false, Message = "There was a problem processing the order" }); } }