public ActionResult AddProductToCart(Guid productid, int quantity) { var visitorID = HttpContext.Profile.UserName; ShoppingCart cart; var portal = PortalCrmConfigurationManager.CreatePortalContext(); var context = portal.ServiceContext; var product = context.CreateQuery("product").FirstOrDefault(p => p.GetAttributeValue <Guid>("productid") == productid); var productDataAdapter = new ProductDataAdapter(product, new Adxstudio.Xrm.Products.PortalContextDataAdapterDependencies(portal, null, Request.RequestContext)); // Check for an existing cart var shoppingCartDataAdapter = new ShoppingCartDataAdapter(new PortalConfigurationDataAdapterDependencies(null, Request.RequestContext), visitorID); var existingShoppingCart = shoppingCartDataAdapter.SelectCart(); // Create cart if it does not already exist. if (existingShoppingCart == null || existingShoppingCart.Entity == null) { cart = shoppingCartDataAdapter.CreateCart() as ShoppingCart; } else { cart = existingShoppingCart as ShoppingCart; } // Add product to cart and redirect to shopping cart page if (cart != null) { cart.AddProductToCart(productid, productDataAdapter.Select().PricingInfo.PriceListName, quantity); } return(RedirectToShoppingCart()); }
public ActionResult CreateReview(string productid, string title, string content, double rating, int maximumRatingValue, string reviewerName, string reviewerLocation, string reviewerEmail, bool recommend) { Guid productID; if (string.IsNullOrEmpty(productid) || !Guid.TryParse(productid, out productID)) { throw new ArgumentException("Please provide a valid product ID."); } var portal = PortalCrmConfigurationManager.CreatePortalContext(); var context = new OrganizationServiceContext(new OrganizationService("Xrm")); var product = GetActiveProduct(productID, context); var productDataAdapter = new ProductDataAdapter(product, new Adxstudio.Xrm.Products.PortalContextDataAdapterDependencies(portal, null, Request.RequestContext)); TryCreateReview(productDataAdapter, title, content, rating, maximumRatingValue, reviewerName, reviewerLocation, reviewerEmail, recommend); return(PartialView("CreateReview", productDataAdapter.Select())); }
private ActionResult GetProductView(Entity product) { var context = PortalCrmConfigurationManager.CreatePortalContext(); var productDataAdapter = new ProductDataAdapter(product.ToEntityReference(), new Adxstudio.Xrm.Products.PortalContextDataAdapterDependencies(context, null, Request.RequestContext)); var imageGalleryNodes = new List <IProductImageGalleryNode>(productDataAdapter.SelectImageGalleryNodes()); var iproduct = productDataAdapter.Select(); var productViewModel = new ProductViewModel { Product = iproduct, ImageGalleryNodes = new ProductImageGalleryViewModel { ImageGalleryNodes = imageGalleryNodes, Product = iproduct }, UserHasReviewed = HttpContext.Request.IsAuthenticated ? productDataAdapter.HasReview(context.User.ToEntityReference()) : productDataAdapter.HasReview(HttpContext.Request.AnonymousID) }; return(View("Product", productViewModel)); }
static void Main(string[] args) { // PetShop OrdersDataSet cds = new OrdersDataSet(); OrdersDataAdapter cda = new OrdersDataAdapter(); ProductDataSet pds = new ProductDataSet(); ProductDataAdapter pda = new ProductDataAdapter(); pda.FillByCategoryId(pds, "BIRDS"); Console.Out.WriteLine(cds.Orders.Rows.Count); IEnumerator en = pds.Product.GetEnumerator(); while (en.MoveNext()) { ProductDataSet.ProductRow row = (ProductDataSet.ProductRow)en.Current; Console.Out.WriteLine(row.ProductId + " " + row.CategoryId + " " + row.Name + " " + row.Descn); } // fill all the records from the permission table. string[] columns = { "ShipCity", "Courier" }; string[] values = { "Nowhere", "Me" }; DbType[] types = { DbType.AnsiString, DbType.AnsiString }; cda.Fill(cds, columns, values, types); Console.Out.WriteLine(cds.Orders.Rows.Count); Console.Out.WriteLine(cds.Orders.FindByOrderId(1) != null ? cds.Orders.FindByOrderId(1).OrderId.ToString() : "Nope"); Console.Out.WriteLine(cds.Orders.FindByOrderId(4) != null ? cds.Orders.FindByOrderId(4).OrderId.ToString() : "Nope"); Console.In.Read(); cds.Clear(); cda.Fill(cds); OrdersDataSet.OrdersRow newRow = cds.Orders.NewOrdersRow(); newRow.OrderDate = DateTime.Now; newRow.ShipAddr1 = "2001 Nowhere"; newRow.ShipCity = "Nowhere"; newRow.ShipState = "Tx"; newRow.ShipZip = "12345"; newRow.UserId = "joe"; newRow.ShipCountry = "USA"; newRow.BillAddr1 = "2001 UHUH"; newRow.BillCity = "Nowhere"; newRow.BillState = "Tx"; newRow.BillZip = "12345"; newRow.UserId = "yoyDu"; newRow.BillCountry = "USA"; newRow.Courier = "Me"; newRow.TotalPrice = 12.12M; newRow.BillToFirstName = "Yaba"; newRow.BillToLastName = "Daba"; newRow.ShipToFirstName = "Yoko"; newRow.ShipToLastName = "Ono"; newRow.AuthorizationNumber = 123; newRow.Locale = "Here"; cds.Orders.AddOrdersRow(newRow); Console.In.Read(); // make some changes and save //OrdersDataSet.OrdersRow editRow = cds.Orders.FindByOrderId(19); //editRow.BillZip = "33333"; //editRow.Courier = "USPS"; cda.Update(cds); //Console.In.Read(); //// reset changes and save //Console.In.Read(); //// Delete row and update //OrdersDataSet.OrdersRow deleteRow = cds.Orders.FindByOrderId(20); //deleteRow.Delete(); //cda.Update(cds); //Console.In.Read(); }