public IActionResult Buy(int id) { OrderQuantityViewModel obj = new OrderQuantityViewModel(); obj.ProductId = id; return(View(obj)); /* * Medicine o = new Medicine(); * * Users obj = new Users { Email = "admin", Password = "******" }; * using (HttpClient client = new HttpClient()) * { * var token = GetToken("https://localhost:44364/api/token", obj); * client.BaseAddress = new Uri("https://localhost:44335/api/"); * // MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); * //client.DefaultRequestHeaders.Accept.Add(contentType); * client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); * client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); * * using (var response = await client.GetAsync("https://localhost:44335/api/medicines" + id)) * { * string apiResponse = await response.Content.ReadAsStringAsync(); * o = JsonConvert.DeserializeObject<Medicine>(apiResponse); * } * } * return View(o);*/ }
public ActionResult Indent() { var q = (from ob in _context.OrderBaskets join bid in _context.BasketItemDetails on ob.BasketID equals bid.BasketID orderby ob.OrderId select new { ob.OrderId, ob.OrderDate, ob.BasketID, ob.BasketName, ob.SKUID, bid.ProductID, bid.ProductName, bid.Quantity, bid.ApplicableFrom, bid.ApplicableTo, bid.KG, }).ToList(); List <OrderQuantityViewModel> prodList = new List <OrderQuantityViewModel>(); var baskTotals = from p in q group p by p.ProductID into productgroup select new { ProductId = productgroup.Key, prodTotalQty = productgroup.Sum(x => x.Quantity), prodTotalKG = Convert.ToDecimal(productgroup.Sum(x => x.KG)) }; var basketIndents = (from bd in q join tb in baskTotals on bd.ProductID equals tb.ProductId orderby bd.ProductID select new { bd.ProductID, bd.ProductName, bd.SKUID, tb.prodTotalQty, tb.prodTotalKG }).Distinct(); List <OrderQuantityViewModel> vm = new List <OrderQuantityViewModel>(); foreach (var item in basketIndents) { OrderQuantityViewModel vmi = new OrderQuantityViewModel(); vmi.ProductID = item.ProductID; vmi.ProductName = item.ProductName; vmi.SKU = item.SKUID; vmi.Quantity = item.prodTotalQty; vmi.KG = item.prodTotalKG; vm.Add(vmi); } return(View(vm)); }
public async Task <IActionResult> Buy(OrderQuantityViewModel oqvm) { //Users obj = new Users { Email = "admin", Password = "******" }; Orders ord = new Orders(); using (HttpClient client = new HttpClient()) { List <Orders> o = new List <Orders>(); Medicine med = new Medicine(); List <Medicine> l = new List <Medicine>(); //var token = GetToken("https://localhost:44364/api/token", obj); client.BaseAddress = new Uri("https://localhost:44335/api/"); // MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json"); //client.DefaultRequestHeaders.Accept.Add(contentType); /* client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); * client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));*/ using (var response = await client.GetAsync("https://localhost:44335/api/medicines/" + oqvm.ProductId)) { string apiResponse = await response.Content.ReadAsStringAsync(); l = JsonConvert.DeserializeObject <List <Medicine> > (apiResponse); } ord.Dateoforder = DateTime.Now; ord.Mid = oqvm.ProductId; ord.Oid = oqvm.OrderId; ord.Totalcost = l[0].Price * oqvm.Quantity; ord.Quantity = oqvm.Quantity; ord.M = null; // l[0].QuantityRemaining = l[0].QuantityRemaining - ord.Quantity; StringContent content = new StringContent(JsonConvert.SerializeObject(ord), Encoding.UTF8, "application/json"); using (var response = await client.PostAsync("https://localhost:44397/api/Orders/", content)) //?id="+oqvm.ProductId+"&q="+oqvm.Quantity { string apiResponse = await response.Content.ReadAsStringAsync(); ord = JsonConvert.DeserializeObject <Orders>(apiResponse); //ord = o[0]; } Medicine medi = new Medicine(); medi.Mid = ord.Mid; medi.Mname = l[0].Mname; medi.Price = l[0].Price; medi.QuantityRemaining = l[0].QuantityRemaining - ord.Quantity; medi.ExpiryDate = l[0].ExpiryDate; l[0].Mid = oqvm.ProductId; //content = new StringContent(JsonConvert.SerializeObject(medi), Encoding.UTF8, "application/json"); /*using (var response = await client.DeleteAsync("https://localhost:44335/api/medicines/"+oqvm.ProductId)) //?id="+oqvm.ProductId+"&q="+oqvm.Quantity * { * string apiResponse = await response.Content.ReadAsStringAsync(); * med = JsonConvert.DeserializeObject<Medicine>(apiResponse); * //ord = o[0]; * }*/ content = new StringContent(JsonConvert.SerializeObject(medi), Encoding.UTF8, "application/json"); using (var response = await client.PutAsync("https://localhost:44335/api/medicines/" + oqvm.ProductId, content)) //?id="+oqvm.ProductId+"&q="+oqvm.Quantity { string apiResponse = await response.Content.ReadAsStringAsync(); med = JsonConvert.DeserializeObject <Medicine>(apiResponse); //ord = o[0]; } } return(View("Reciept", ord)); }