/// <summary> /// Start a new basket /// </summary> /// <param name="dataContextFactory">Data context factory</param> /// <returns>An instance of a basketwrapper serving a new transaction</returns> public static BasketWrapper CreateNewByIdentity(IDataContextFactory dataContextFactory) { var basket = new BasketWrapper(dataContextFactory.CreateByUser()); basket.Transaction = new Transaction {CreatedDateTime = DateTime.Now}; return basket; }
/// <summary> /// Start a new basket /// </summary> /// <param name="dataContextFactory">Data context factory</param> /// <returns>An instance of a basketwrapper serving a new transaction</returns> public static BasketWrapper CreateNewByVendor(IDataContextFactory dataContextFactory, Guid vendorId) { var basket = new BasketWrapper(new DataContextByAuthorizedVendor(vendorId)); basket.Transaction = new Transaction { CreatedDateTime = DateTime.Now }; return(basket); }
/// <summary> /// Start a new basket /// </summary> /// <param name="dataContextFactory">Data context factory</param> /// <returns>An instance of a basketwrapper serving a new transaction</returns> public static BasketWrapper CreateNewByIdentity(IDataContextFactory dataContextFactory) { var basket = new BasketWrapper(dataContextFactory.CreateByUser()); basket.Transaction = new Transaction { CreatedDateTime = DateTime.Now }; return(basket); }
/// <summary> /// Get a basketwrapper based on a provided transactionId /// </summary> /// <param name="dataContextFactory">Data context factory</param> /// <param name="transactionId">Id of the transaction to load in the basket</param> /// <returns>An instance of a basketwrapper serving the transaction</returns> /// <remarks> /// At first attempt the a datacontext based on userIdentity is applied. /// If userIdentity datacontext does not contain requested transaction, user does not yet /// have access to transaction (new user or new vendor). Use datacontext based on /// transactionId instead. /// </remarks> public static BasketWrapper CreateByTransaction(IDataContextFactory dataContextFactory, Guid transactionId) { var basket = new BasketWrapper(dataContextFactory.CreateByTransaction(transactionId)); var transactionLoaded = basket.LoadTransaction(transactionId); if (!transactionLoaded) { throw new Exception(); } return(basket); }
/// <summary> /// Get a basketwrapper based on a provided transactionId /// </summary> /// <param name="dataContextFactory">Data context factory</param> /// <param name="transactionId">Id of the transaction to load in the basket</param> /// <returns>An instance of a basketwrapper serving the transaction</returns> /// <remarks> /// At first attempt the a datacontext based on userIdentity is applied. /// If userIdentity datacontext does not contain requested transaction, user does not yet /// have access to transaction (new user or new vendor). Use datacontext based on /// transactionId instead. /// </remarks> public static BasketWrapper CreateByTransaction(IDataContextFactory dataContextFactory, Guid transactionId) { var basket = new BasketWrapper(dataContextFactory.CreateByTransaction(transactionId)); var transactionLoaded = basket.LoadTransaction(transactionId); if (!transactionLoaded) { throw new Exception(); } return basket; }
protected TransactionResult ProcessTransaction(TransactionRequest transaction, BasketWrapper basket) { if (transaction == null) return new TransactionResult { CreatedSuccessfull = false, ErrorMessage = "Invalid transaction format provided" }; if (string.IsNullOrEmpty(transaction.PurchaserName)) return new TransactionResult { CreatedSuccessfull = false, ErrorMessage = "No purchaser name set" }; if (string.IsNullOrEmpty(transaction.PurchaserEmail)) return new TransactionResult { CreatedSuccessfull = false, ErrorMessage = "No purchaser email set" }; if (!Strings.IsEmail(transaction.PurchaserEmail)) return new TransactionResult { CreatedSuccessfull = false, ErrorMessage = string.Format("Purchaser email '{0}' is not an e-mailaddress", transaction.PurchaserEmail) }; try { basket.AddItems(transaction.PurchasedSkus); basket.Transaction.OriginalRequest = GetOriginalRequestValues(); basket.Transaction.PurchaserName = transaction.PurchaserName; basket.Transaction.PurchaserEmail = transaction.PurchaserEmail; basket.ExecuteCreate(); mailService.SendTransactionMail(transaction.PurchaserName, transaction.PurchaserEmail, basket.Transaction.TransactionId); return new TransactionResult { CreatedSuccessfull = true }; } catch (BusinessRuleValidationException e) { // ReSharper disable RedundantToStringCall, expilicitly call diverted implementation of ToString() return new TransactionResult { CreatedSuccessfull = false, ErrorMessage = string.Format("Could not process transaction: {0}", e.ToString()) }; // ReSharper restore RedundantToStringCall } catch (Exception e) { return new TransactionResult { CreatedSuccessfull = false, ErrorMessage = string.Format("Could not process transaction due to exception: {0}", e.Message) }; } }
/// <summary> /// Start a new basket /// </summary> /// <param name="dataContextFactory">Data context factory</param> /// <returns>An instance of a basketwrapper serving a new transaction</returns> public static BasketWrapper CreateNewByVendor(IDataContextFactory dataContextFactory, Guid vendorId) { var basket = new BasketWrapper(new DataContextByAuthorizedVendor(vendorId)); basket.Transaction = new Transaction { CreatedDateTime = DateTime.Now }; return basket; }