public ActionResult AddProduct(ProductViewModel model) { using (IProductsChannel channel = channelFactory.CreateChannel()) { ProductData newProduct = new ProductData() { Name = model.NewProduct.Name, Quantity = model.NewProduct.Quantity }; channel.AddProduct(newProduct); model.ProductList = from prod in channel.GetProducts() select new Product { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity }; // Return a view of the products inventory. return(this.View("Index", model)); } }
public ActionResult About() { // Declare the channel factory. ChannelFactory <IProductsChannel> channelFactory; // Create shared access signature token credentials for authentication. channelFactory = new ChannelFactory <IProductsChannel>(new NetTcpRelayBinding(), "sb://ekybfdrelay.servicebus.windows.net"); channelFactory.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider( "RootManageSharedAccessKey", "oxnOBrCE8HNpgCI/fjO4Sf160k64jeZPJOzKIsdaYP0=") }); ViewBag.Message = "Your application description page."; using (IProductsChannel channel = channelFactory.CreateChannel()) { var model = from prod in channel.GetProducts() select new ProductData { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity }; return(View(model)); } }
public ActionResult Index(string Identifier, string ProductName) { using (IProductsChannel channel = channelFactory.CreateChannel()) { return(View(from prod in channel.GetProducts() select new Product { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity })); } }
public ActionResult Edit(string id) { using (IProductsChannel channel = channelFactory.CreateChannel()) { var product = from prod in channel.GetProducts() where prod.Id == id select new Product { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity }; return(View(product.First())); } }
public ActionResult Edit(Product product) { if (ModelState.IsValid) { using (IProductsChannel channel = channelFactory.CreateChannel()) { var productData = product.MapTo(product); channel.UpdataProduct(productData); return(RedirectToAction("Index")); } } return(View(product)); }
public ActionResult Index(string Identifier, string ProductName) { //var products = new List<Product> // {new Product {Id = Identifier, Name = ProductName}}; //return View(products); // Return a view of the products inventory. using (IProductsChannel channel = channelFactory.CreateChannel()) { return(View(from prod in channel.GetProducts() select new Product { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity })); } }
public ActionResult Index() { using (IProductsChannel channel = channelFactory.CreateChannel()) { // Return a view of the products inventory return(this.View(from prod in channel.GetProducts() select new Product { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity })); } }
// Return a view of the products inventory. public ActionResult Index(string Identifier, string ProductName) { using (IProductsChannel channel = channelFactory.CreateChannel()) { ProductViewModel product = new ProductViewModel(); product.ProductList = from prod in channel.GetProducts() select new Product { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity }; // Return a view of the products inventory. return(this.View(product)); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log) { var remoteAddress = GetEnvironmentVariable("RemoteAddress"); var rootManageSharedAccessKey = GetEnvironmentVariable("RootManageSharedAccessKey"); var sendKeyName = GetEnvironmentVariable("SendKeyName"); // Create shared access signature token credentials for authentication. channelFactory = new ChannelFactory <IProductsChannel>(new NetTcpRelayBinding(), remoteAddress); channelFactory.Endpoint.Behaviors.Add(new TransportClientEndpointBehavior { TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider( sendKeyName, rootManageSharedAccessKey) }); log.Info("C# HTTP trigger function processed a request."); using (IProductsChannel channel = channelFactory.CreateChannel()) { // Return a view of the products inventory. var result = from prod in channel.GetProducts() select new Product { Id = prod.Id, Name = prod.Name, Quantity = prod.Quantity }; string jsonToReturn = JsonConvert.SerializeObject(result, Formatting.Indented); log.Info(jsonToReturn); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json") }); // return req.CreateResponse(HttpStatusCode.OK, result); } }