/// <summary>
 /// 0=Success, 1=InvalidExpirationDate, 2=InvalidCvv, 3=InvalidProduct, 4=InvalidPaymentAmount
 /// </summary>        
 public int DoPurchase(string purchaseRequest)
 {
     JavaScriptSerializer serializer = new JavaScriptSerializer();
     PurchaseRequest request = (PurchaseRequest)serializer.Deserialize(purchaseRequest, typeof(PurchaseRequest));
     using (MundiShopEntities db = new MundiShopEntities())
     {
         if (request.CreditCardExpirationYear < DateTime.Now.Year ||
         (request.CreditCardExpirationYear == DateTime.Now.Year && request.CreditCardExpirationMonth < DateTime.Now.Month))
         {
             return 1;
         }
         if (String.IsNullOrWhiteSpace(request.CreditCardCvv) || request.CreditCardCvv.Length != 3)
             return 2;
         Product product = db.Product.FirstOrDefault(p => p.Id == request.ProductId);
         if (product == null)
             return 3;
         if (request.AmountPaid != product.Price)
             return 4;
         Purchase purchase = new Purchase()
         {
             CreditCardCvv = request.CreditCardCvv,
             CreditCardExpirationMonth = request.CreditCardExpirationMonth,
             CreditCardExpirationYear = request.CreditCardExpirationYear,
             CreditCardFlag = request.CreditCardFlag,
             CreditCardNumber = request.CreditCardNumber,
             CustomerName = request.CustomerName,
             dateCreate= DateTime.Now
         };
         purchase.Product.Add(product);
         db.Purchase.AddObject(purchase);
         db.SaveChanges();
         return 0;
     }
 }
 public ProductResponse[] GetAllProducts()
 {
     using (MundiShopEntities db = new MundiShopEntities())
     {
         List<ProductResponse> retVal = (from Product product in db.Product.OrderBy(p => p.Name)
             select new ProductResponse()
             {
                 Id = product.Id,
                 Name = product.Name,
                 Description = product.Description,
                 Price = product.Price
             }).ToList();
         return retVal.ToArray();
     }
 }