public async Task <ActionResult> GetProductById(string id) { //string strint = id.Trim().ToString(); var intid = Convert.ToInt32(id); ProductMasterModel pro = new ProductMasterModel(); ProductMasterModelSingleRootObject obj = new ProductMasterModelSingleRootObject(); string url = GetUrl(2); url = url + "Product/GetProductById?id=" + Convert.ToInt32(intid) + ""; using (HttpClient client = new HttpClient()) { HttpResponseMessage responseMessage = await client.GetAsync(url); if (responseMessage.IsSuccessStatusCode) { var response = responseMessage.Content.ReadAsStringAsync().Result; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; obj = JsonConvert.DeserializeObject <ProductMasterModelSingleRootObject>(response, settings); pro = obj.data; TempData["item"] = pro; } } return(RedirectToAction("Index")); }
public async Task <ActionResult> AddNewProduct(FormCollection fc, HttpPostedFileBase file) { //if (ModelState.IsValid) //{ int ProductId = 0; ProductMasterModel model = new ProductMasterModel(); string productId = fc["ProductId"]; string CategoryName = fc["CategoryName"]; string ProductName = fc["ProductName"]; string UnitPrice = fc["UnitPrice"]; string GST = fc["GST"]; string Discount = fc["Discount"]; string TaxType = fc["TaxType"]; bool Lock = Convert.ToBoolean(fc["Lock"].Split(',')[0]);; string UOM = fc["UOM"]; string ProductDetails = fc["ProductDetails"]; string DeliveryCharge = fc["DeliveryCharge"]; //string ProductId = Convert.ToString(model.ProductId); //string ProductDetails = model.ProductDetails; //string CategoryName = model.CategoryName; //string ProductName = model.ProductName; //string UnitPrice = Convert.ToString(model.UnitPrice); //string GST = Convert.ToString(model.GST); //string Discount = Convert.ToString(model.Discount); //string TaxType = Convert.ToString(model.TaxType); ////bool Lock = Convert.ToBoolean(fc["Lock"].Split(',')[0]); ; //bool Lock = model.Lock; //string UOM = Convert.ToString(model.UOM); ////string ProductDetails = fc["ProductDetails"]; string url = GetUrl(2); url = url + "Product/AddNewProduct?ProductId=" + productId + "&CategoryName=" + CategoryName + "&ProductName=" + ProductName + "&UnitPrice=" + UnitPrice + "&GST=" + GST + "&Discount=" + Discount + "&TaxType=" + TaxType + "&Lock=" + Lock + "&UOM=" + UOM + "&ProductDetails=" + ProductDetails + "&DeliveryCharge=" + DeliveryCharge + ""; using (HttpClient client = new HttpClient()) { HttpResponseMessage responseMessage = await client.GetAsync(url); ProductMasterModelSingleRootObject result = new ProductMasterModelSingleRootObject(); if (responseMessage.IsSuccessStatusCode) { var response = responseMessage.Content.ReadAsStringAsync().Result; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; result = JsonConvert.DeserializeObject <ProductMasterModelSingleRootObject>(response, settings); if (result.data.ProductId == 0) { ProductId = Convert.ToInt32(productId); } else { ProductId = result.data.ProductId; } if (ProductId > 0) { try { var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", "jpeg", ".JPG", }; //string imagepath = "http://103.233.79.234/Data/SJB_Android/LocalityPictures/"; model.ProductPicturesUrl = file.ToString(); //getting complete url var fileName = Path.GetFileName(file.FileName); //getting only file name(ex-ganesh.jpg) var ext = Path.GetExtension(file.FileName); //getting the extension(ex-.jpg) if (allowedExtensions.Contains(ext)) //check what type of extension { string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension string myfile = +ProductId + ext; //appending the name with id // store the file inside ~/project folder(Img) //var path = Path.Combine(imagepath, myfile); string path = @"C:\inetpub\wwwroot\Data\SJB_Android\ProductPictures\" + Server.HtmlEncode(myfile); model.ProductPicturesUrl = path; //file.SaveAs(path); var fInfo = new FileInfo(myfile); if (!fInfo.Exists) { file.SaveAs(path); } else { System.IO.File.Copy(path, path, true); } } } catch (Exception ex) { } } else { ViewBag.message = "Please choose only Image file"; } } return(RedirectToAction("Index")); } //} //else //{ // return RedirectToAction("Index"); //} }