public async Task <ActionResult> GetCategoryById(int id) { //string strint = id.Trim().ToString(); //var intid = Convert.ToInt32(strint); CategoryMasterModel pro = new CategoryMasterModel(); CategoryMasterModelSingleRootObject obj = new CategoryMasterModelSingleRootObject(); string url = GetUrl(2); url = url + "Category/GetCategoryById?id=" + Convert.ToInt32(id) + ""; 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 <CategoryMasterModelSingleRootObject>(response, settings); pro = obj.data; TempData["item"] = pro; } } return(RedirectToAction("Index")); }
public async Task <ActionResult> AddNewCategory(FormCollection fc, HttpPostedFileBase file) { if (ModelState.IsValid) { ViewBag.StoreId = Session["StoreId"].ToString(); int categoryid = 0; string storeid = ""; CategoryMasterModel model = new CategoryMasterModel(); string CategoryId = fc["CategoryId"]; string categoryname = fc["CategoryName"]; string menuid = fc["MenuName"]; if (ViewBag.StoreId == "0") { storeid = fc["StoreName"]; } else { storeid = ViewBag.StoreId; } string description = fc["CategoryDescription"]; string url = GetUrl(2); url = url + "Category/AddNewCategory?CategoryId=" + CategoryId + "&CategoryName=" + categoryname + "&menuid=" + menuid + "&storeid=" + storeid + "&CategoryDescription=" + description + ""; using (HttpClient client = new HttpClient()) { HttpResponseMessage responseMessage = await client.GetAsync(url); CategoryMasterModelSingleRootObject result = new CategoryMasterModelSingleRootObject(); if (responseMessage.IsSuccessStatusCode) { var response = responseMessage.Content.ReadAsStringAsync().Result; var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; result = JsonConvert.DeserializeObject <CategoryMasterModelSingleRootObject>(response); if (result.data.CategoryId == 0) { categoryid = Convert.ToInt32(CategoryId); } else { categoryid = result.data.CategoryId; } if (categoryid > 0) { try { var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", "jpeg", ".JPG", }; //string imagepath = "http://103.233.79.234/Data/SJB_Android/CategoryPictures/"; model.CategoryPictures = 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 = +categoryid + 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\CategoryPictures\" + Server.HtmlEncode(myfile); model.CategoryPictures = 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")); } }