Esempio n. 1
0
        public OperationResult <Order> PlaceOrder(Cart cart)
        {
            const int MAX_RETRY = 10;

            if (cart == null)
            {
                throw new ArgumentNullException("cart");
            }

            Dictionary <string, string> customerInfo = new Dictionary <string, string>();

            customerInfo.Add("Email", cart.Customer.Email);
            customerInfo.Add("Phone", cart.Customer.Phone);
            customerInfo.Add("Address", cart.Customer.Address);
            customerInfo.Add("CodeID", cart.Customer.Id.ToString());
            //customerInfo.Add("Name", cart.Customer.Email);

            cart.Order.Esnecils = new List <Esnecil>();
            foreach (ProductPrice productPrice in cart.ProductPrices)
            {
                RawEsnecil rawEsnecil = _esnecilGenerator.GenerateLicense(customerInfo);
                Esnecil    esnecil    = rawEsnecil.ToEsnecil();
                esnecil.ProductPriceId = productPrice.Id;
                cart.Order.Esnecils.Add(esnecil);
            }

            for (int i = 1; i <= MAX_RETRY; i++)
            {
                try
                {
                    Invoice invoice = _invoiceManager.GetNextInvoiceNo();
                    cart.Order.InvoiceNo = invoice.InvoiceNo;
                    cart.Order.SerialNo  = invoice.SerialNo;

                    _repository.Add(cart.Order);
                    _repository.Save();

                    break;
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("Violation of UNIQUE KEY constraint"))
                    {
                        if (i == MAX_RETRY)
                        {
                            throw new Exception("Violation of UNIQUE KEY constraint. Cannot insert duplicate key in object. The statement has been terminated. Please try again.");
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(new OperationResult <Order>(true)
            {
                Entity = cart.Order
            });
        }
Esempio n. 2
0
        public static Esnecil ToEsnecil(this RawEsnecil rawEsnecil)
        {
            if (rawEsnecil == null)
            {
                throw new ArgumentNullException("rawEsnecil cannot be null!");
            }

            Esnecil esnecil = new Esnecil()
            {
                EsnecilCode          = rawEsnecil.EsnecilCode,
                MachineKey           = rawEsnecil.MachineKey,
                EnableTamperChecking = rawEsnecil.EnableTamperChecking,
                DetectDateRollback   = rawEsnecil.DetectDateRollback,
                SerialCode           = rawEsnecil.SerialCode,
                RawUserData          = rawEsnecil.RawUserData,
                NoOfUsers            = rawEsnecil.NoOfUsers,
                GeneratedOn          = rawEsnecil.GeneratedOn,
            };

            return(esnecil);
        }