public List <Service> GetPostCount() { var result = new List <Service>(); try { string query = "select ID,Name,TotalPostsByService(ID) as SERVICETYPEID from Service"; var dt = DataAccess.GetDataTable(query); if (dt != null && dt.Rows.Count != 0) { for (int i = 0; i < dt.Rows.Count; i++) { Service u = ConvertToEntity(dt.Rows[i]); result.Add(u); } } dt = DataAccess.GetDataTable("BEGIN total_donation.find_amt(2); END;"); } catch (Exception ex) { } return(result); }
private Service ConvertToEntity(DataRow row) { try { Service u = new Service(); u.ID = Int32.Parse(row["ID"].ToString()); u.Name = row["Name"].ToString(); u.ServiceTypeID = Int32.Parse(row["ServiceTypeID"].ToString()); return(u); } catch (Exception) { return(null); } }
private bool IsValid(Service obj, Result <Service> result) { if (!ValidationHelper.IsStringValid(obj.Name)) { result.HasError = true; result.Message = "Invalid Name"; return(false); } if (!ValidationHelper.IsIntValid(obj.ServiceTypeID.ToString())) { result.HasError = true; result.Message = "Invalid service type"; return(false); } return(true); }
public Result <Service> Save(Service service) { var result = new Result <Service>(); try { string query = "select * from Service where ID=" + service.ID; var dt = DataAccess.GetDataTable(query); if (dt == null || dt.Rows.Count == 0) { query = "BEGIN insertService('" + service.Name + "'," + service.ServiceTypeID + "); END;"; } else { query = "update Service set Name='" + service.Name + "',ServiceTypeID=" + service.ServiceTypeID + "where ID=" + service.ID; } if (!IsValid(service, result)) { return(result); } DataAccess.ExecuteQuery(query); result.Data = service; //result.HasError = DataAccess.ExecuteQuery(query) <= 0; //if (result.HasError) // result.Message = "Something Went Wrong"; //else //{ // result.Data = service; //} } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
public List <Service> GetAll() { var result = new List <Service>(); try { string query = "select * from Service"; var dt = DataAccess.GetDataTable(query); if (dt != null && dt.Rows.Count != 0) { for (int i = 0; i < dt.Rows.Count; i++) { Service u = ConvertToEntity(dt.Rows[i]); result.Add(u); } } } catch (Exception ex) { } return(result); }