//Convert DataTable To object method public BusinessReviewClass ConvertToOjbect(DataTable dt) { BusinessReviewClass obj_BusinessReview = new BusinessReviewClass(); for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToString(dt.Rows[i]["Businessreviewid"]) != "") { obj_BusinessReview.Businessreviewid = Convert.ToInt32(dt.Rows[i]["Businessreviewid"]); } if (Convert.ToString(dt.Rows[i]["Businessid"]) != "") { obj_BusinessReview.Businessid = Convert.ToInt32(dt.Rows[i]["Businessid"]); } if (Convert.ToString(dt.Rows[i]["Name"]) != "") { obj_BusinessReview.Name = Convert.ToString(dt.Rows[i]["Name"]); } if (Convert.ToString(dt.Rows[i]["Email"]) != "") { obj_BusinessReview.Email = Convert.ToString(dt.Rows[i]["Email"]); } if (Convert.ToString(dt.Rows[i]["Review"]) != "") { obj_BusinessReview.Review = Convert.ToString(dt.Rows[i]["Review"]); } if (Convert.ToString(dt.Rows[i]["Rating"]) != "") { obj_BusinessReview.Rating = Convert.ToString(dt.Rows[i]["Rating"]); } if (Convert.ToString(dt.Rows[i]["Isactive"]) != "") { obj_BusinessReview.Isactive = Convert.ToBoolean(dt.Rows[i]["Isactive"]); } if (Convert.ToString(dt.Rows[i]["Addedon"]) != "") { obj_BusinessReview.Addedon = Convert.ToDateTime(dt.Rows[i]["Addedon"]); } if (Convert.ToString(dt.Rows[i]["Addedbyip"]) != "") { obj_BusinessReview.Addedbyip = Convert.ToString(dt.Rows[i]["Addedbyip"]); } if (Convert.ToString(dt.Rows[i]["Isdeleted"]) != "") { obj_BusinessReview.Isdeleted = Convert.ToBoolean(dt.Rows[i]["Isdeleted"]); } } return(obj_BusinessReview); }
//update edited object public BusinessReviewClass updateObject(BusinessReviewClass obj) { try { BusinessReviewClass oldObj = selectById(obj.Businessreviewid); if (obj.Businessid == null) { obj.Businessid = oldObj.Businessid; } if (obj.Name == null) { obj.Name = oldObj.Name; } if (obj.Email == null) { obj.Email = oldObj.Email; } if (obj.Review == null) { obj.Review = oldObj.Review; } if (obj.Rating == null) { obj.Rating = oldObj.Rating; } if (obj.Isactive == null) { obj.Isactive = oldObj.Isactive; } if (obj.Addedon == null) { obj.Addedon = oldObj.Addedon; } if (obj.Addedbyip == null) { obj.Addedbyip = oldObj.Addedbyip; } if (obj.Isdeleted == null) { obj.Isdeleted = oldObj.Isdeleted; } return(obj); } catch (Exception ex) { throw new Exception(ex.Message); } }
//update data into database public Int32?update(BusinessReviewClass obj) { try { obj_con.clearParameter(); obj = updateObject(obj); createParameter(obj, DBTrans.Update); obj_con.BeginTransaction(); obj_con.ExecuteNoneQuery("sp_BusinessReview_update", CommandType.StoredProcedure); obj_con.CommitTransaction(); return(obj.Businessreviewid = Convert.ToInt32(obj_con.getValue("@Businessreviewid"))); } catch (Exception ex) { obj_con.RollbackTransaction(); throw new Exception("sp_BusinessReview_update:" + ex.Message); } }
//Select Constructor public BusinessReviewCtl(Int32?id) { obj_con = new ConnectionCls(); BusinessReviewClass obj_Bus = new BusinessReviewClass(); using (DataTable dt = selectdatatable(id)) { if (dt.Rows.Count > 0) { obj_Bus.Businessreviewid = Convert.ToInt32(dt.Rows[0]["Businessreviewid"]); obj_Bus.Businessid = Convert.ToInt32(dt.Rows[0]["Businessid"]); obj_Bus.Name = Convert.ToString(dt.Rows[0]["Name"]); obj_Bus.Email = Convert.ToString(dt.Rows[0]["Email"]); obj_Bus.Review = Convert.ToString(dt.Rows[0]["Review"]); obj_Bus.Rating = Convert.ToString(dt.Rows[0]["Rating"]); obj_Bus.Isactive = Convert.ToBoolean(dt.Rows[0]["Isactive"]); obj_Bus.Addedon = Convert.ToDateTime(dt.Rows[0]["Addedon"]); obj_Bus.Addedbyip = Convert.ToString(dt.Rows[0]["Addedbyip"]); obj_Bus.Isdeleted = Convert.ToBoolean(dt.Rows[0]["Isdeleted"]); } } }
//create parameter public void createParameter(BusinessReviewClass obj, DB_con.DBTrans trans) { try { obj_con.clearParameter(); if (Convert.ToString(obj.Businessid) != "") { obj_con.addParameter("@Businessid", string.IsNullOrEmpty(Convert.ToString(obj.Businessid)) ? 0 : obj.Businessid); } else { obj_con.addParameter("@Businessid", DBNull.Value); } if (Convert.ToString(obj.Name) != "") { obj_con.addParameter("@Name", string.IsNullOrEmpty(Convert.ToString(obj.Name)) ? "" : obj.Name); } else { obj_con.addParameter("@Name", DBNull.Value); } if (Convert.ToString(obj.Email) != "") { obj_con.addParameter("@Email", string.IsNullOrEmpty(Convert.ToString(obj.Email)) ? "" : obj.Email); } else { obj_con.addParameter("@Email", DBNull.Value); } if (Convert.ToString(obj.Review) != "") { obj_con.addParameter("@Review", string.IsNullOrEmpty(Convert.ToString(obj.Review)) ? "" : obj.Review); } else { obj_con.addParameter("@Review", DBNull.Value); } if (Convert.ToString(obj.Rating) != "") { obj_con.addParameter("@Rating", string.IsNullOrEmpty(Convert.ToString(obj.Rating)) ? "" : obj.Rating); } else { obj_con.addParameter("@Rating", DBNull.Value); } if (Convert.ToString(obj.Isactive) != "") { obj_con.addParameter("@Isactive", string.IsNullOrEmpty(Convert.ToString(obj.Isactive)) ? false : obj.Isactive); } else { obj_con.addParameter("@Isactive", DBNull.Value); } if (Convert.ToString(obj.Addedon) != "") { obj_con.addParameter("@Addedon", string.IsNullOrEmpty(Convert.ToString(obj.Addedon)) ? Convert.ToDateTime("1900-01-01") : obj.Addedon); } else { obj_con.addParameter("@Addedon", DBNull.Value); } if (Convert.ToString(obj.Addedbyip) != "") { obj_con.addParameter("@Addedbyip", string.IsNullOrEmpty(Convert.ToString(obj.Addedbyip)) ? "" : obj.Addedbyip); } else { obj_con.addParameter("@Addedbyip", DBNull.Value); } if (Convert.ToString(obj.Isdeleted) != "") { obj_con.addParameter("@Isdeleted", string.IsNullOrEmpty(Convert.ToString(obj.Isdeleted)) ? false : obj.Isdeleted); } else { obj_con.addParameter("@Isdeleted", DBNull.Value); } if (Convert.ToString(obj.Businessreviewid) != "") { obj_con.addParameter("@Businessreviewid", Convert.ToInt32(obj.Businessreviewid), trans); } else { obj_con.addParameter("@Businessreviewid", DBNull.Value); } } catch (Exception ex) { throw ex; } }