public static List <Vitem> convertitemstolist(DataSet ds) { List <Vitem> list = new List <Vitem>(); try { if (ds.Tables[0] != null) { rowcount = ds.Tables[0].Rows.Count; for (int i = 0; i < rowcount; i++) { Vitem u = new Vitem(); u.itm_id = Int32.Parse(ds.Tables[0].Rows[i]["itm_id"].ToString()); u.itemname = ds.Tables[0].Rows[i]["it_name"].ToString(); u.cat_img = ds.Tables[0].Rows[i]["cat_img"].ToString(); u.pscName = ds.Tables[0].Rows[i]["pscName"].ToString(); //u.prod_subcat_id = Int32.Parse(ds.Tables[0].Rows[i]["prod_subcat_id"].ToString()); //u.prod_cat_id = Int32.Parse(ds.Tables[0].Rows[i]["prod_cat_id"].ToString()); //u.PID = Int32.Parse(ds.Tables[0].Rows[i]["PID"].ToString()); u.pcName = ds.Tables[0].Rows[i]["pcName"].ToString(); u.PName = ds.Tables[0].Rows[i]["PName"].ToString(); list.Add(u); } } else { list = null; } } catch (EvaluateException ex) { //handel sql excepetions Console.WriteLine(ex.Message + " in TypeConvert ConvertDStoBO()"); } catch (Exception ex) { //handel exceptions Console.WriteLine(ex.Message + " in TypeConvert ConvertDStoBO()"); } return(list); }
public int insimgcats([FromBody] Vitem vitem) { IARresponse = BadRequest(); string name = RandomNamesForProfiles.GetRandomString(6); string fileExt = Path.GetExtension(vitem.imgname); string extname = name + "" + fileExt; vitem.imgname = extname; int i = objVendorDb.vitemadding(vitem); if (i != 0) { IARresponse = Ok(new { res = "items added successfully" }); if (vitem.cat_img != "") { CommonModel model = new CommonModel(); string root = _hostingEnvironment.WebRootPath + "/images/Products/ProductsCategory/ProductsSubCategory/itemimg"; //var fname = Path.GetFileName(vitem.cat_img); var path = Path.Combine(root, extname); //string[] arrfiles = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/vendor/")); string[] arrfiles = Directory.GetFiles(root); //var files = HttpContext.Request.Form.Files; //Check if directory exist if (!System.IO.Directory.Exists(root)) { System.IO.Directory.CreateDirectory(root); //Create directory if it doesn't exist } var file = i + "_" + vitem.imgname; //string name = RandomNamesForProfiles.Encryptword(file); byte[] imageBytes = Convert.FromBase64String(vitem.cat_img); string pathname = i + "_" + name; System.IO.File.WriteAllBytes(path, imageBytes); IARresponse = Ok(new { res = "Vendor Items added Successfully" }); //if (vitem.imgname != null && vitem.imgname.Length > 0) //{ // var file = i + "_" + vitem.imgname; // //string name = RandomNamesForProfiles.Encryptword(file); // byte[] imageBytes = Convert.FromBase64String(vitem.cat_img); // System.IO.File.WriteAllBytes(path, imageBytes); // var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "images"); // //if (file.Length > 0) // //{ // // //var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file); // // var fileName = Path.GetExtension(file); // // using (var fileStream = new FileStream(Path.Combine(root, file), FileMode.Create)) // // { // // vitem.cat_img = fileName; // // } // //} //} foreach (string filename in arrfiles) { if (System.IO.File.Exists(filename)) { if (fname == Path.GetFileName(filename)) { string fileNamenext = Path.GetFileNameWithoutExtension(filename); // FileInfo fffinfo = new FileInfo(Path.Combine(fileNamenext+vid+fileExt)); FileInfo finfo = new FileInfo(filename); finfo.CopyTo(path + "_" + i + fileExt, true); System.IO.File.Delete(filename); } } } } } else { IARresponse = BadRequest(new { err = "Try..again" }); } return(i); }
public int vitemadding(Vitem vitem) { string str = db.Sconnection(); int i = 0; //string ImageExt = ""; //if (vitem.cat_img != null || vitem.cat_img != "") //{ // string fname = vitem.imgname; // ImageExt =Path.GetFileName(fname); //} CmdCAP = new SqlCommand(); CmdCAP.Parameters.Clear(); CmdCAP.Parameters.Add(CommonDbFunctions.AddParameter("@vid", SqlDbType.Int, 0, vitem.vendorid)); CmdCAP.Parameters.Add(CommonDbFunctions.AddParameter("@pscid", SqlDbType.Int, 0, vitem.prod_subcat_id)); CmdCAP.Parameters.Add(CommonDbFunctions.AddParameter("@img", SqlDbType.VarChar, 1000, string.IsNullOrEmpty(vitem.imgname) ? SqlString.Null : vitem.imgname)); CmdCAP.Parameters.Add(CommonDbFunctions.AddParameter("@it_name", SqlDbType.VarChar, 1000, string.IsNullOrEmpty(vitem.itemname) ? SqlString.Null : vitem.itemname)); //CmdCAP.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output; //using (ConCAP = new SqlConnection()) //{ // try // { // ErrorMessage = CommonDbFunctions.SqlCommandExecution(CommandType.StoredProcedure, "sp_itemsadding", CmdCAP); // if(ErrorMessage=="") // i= Convert.ToInt32(CmdCAP.Parameters["@id"].Value); // } // catch (SqlException ex) // { // ErrorMessage = ex.Message; // } //} CmdCAP.CommandText = "sp_itemsadding"; CmdCAP.CommandType = CommandType.StoredProcedure; using (ConCAP = new SqlConnection(str)) { try { ConCAP.Open(); tranCAP = ConCAP.BeginTransaction(); CmdCAP.Connection = ConCAP; CmdCAP.Transaction = tranCAP; CmdCAP.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output; //CmdCAP.Parameters.Add(CommonDbFunctions.AddParameter("@id", SqlDbType.Int, 0, ParameterDirection.Output)); int j = CmdCAP.ExecuteNonQuery(); tranCAP.Commit(); i = Convert.ToInt32(CmdCAP.Parameters["@id"].Value); } catch (Exception ex) { ErrorMessage = ex.Message; if (tranCAP != null) { tranCAP.Rollback(); } } } return(i); }