public static string AddSubCategory(string SubCategoryName, int CategoryID, bool IsDelete, string Image, string ImageName, string Heading, string Description, string Page_Image, string Page_Image_Name) { try { PAWDStoreEntities context = new PAWDStoreEntities(); byte[] ImageFile = null; byte[] PageImage = null; if (Image != null && !string.IsNullOrEmpty(Image)) { ImageFile = Convert.FromBase64String(Image); } if (Page_Image != null && !string.IsNullOrEmpty(Page_Image)) { PageImage = Convert.FromBase64String(Page_Image); } var get_all_sub_cat = context.SubCategory_Master.OrderBy(x => x.Sortable).ToList(); int sort = 2; foreach (var i in get_all_sub_cat) { i.Sortable = sort++; context.SaveChanges(); } if (ImageFile != null) { //string filePath = HttpContext.Current.Server.MapPath(string.Format("~/SubCategoryImage/{0}", ImageFile)); string filePath = HttpContext.Current.Server.MapPath(string.Format("~/SubCategoryImage/" + ImageName + "")); File.WriteAllBytes(filePath, ImageFile); } if (PageImage != null) { //string filePath = HttpContext.Current.Server.MapPath(string.Format("~/SubCategoryHeaderImage/{0}", PageImage)); string filePath = HttpContext.Current.Server.MapPath(string.Format("~/SubCategoryHeaderImage/" + Page_Image_Name + "")); File.WriteAllBytes(filePath, ImageFile); } var status = context.SubCategoryInsert(SubCategoryName, CategoryID, IsDelete, null, false, ImageName, 1, Heading, Description, null, Page_Image_Name, string.Empty).FirstOrDefault(); return(JsonConvert.SerializeObject(status)); } catch (Exception ex) { throw ex.InnerException; } }