public Guid InsertCity(CityBO city) { try { string sql = "dbo.fn_insert_city"; conn = new NpgsqlConnection(connString); conn.Open(); NpgsqlTransaction tran = conn.BeginTransaction(); using (var cmd = new NpgsqlCommand(sql, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("_cityid", NpgsqlTypes.NpgsqlDbType.Varchar, city.cityid); cmd.Parameters.AddWithValue("_cityname", NpgsqlTypes.NpgsqlDbType.Varchar, city.cityname); var carrierKey = cmd.ExecuteScalar(); tran.Commit(); return(Guid.Parse(carrierKey.ToString())); } } catch (Exception msg) { throw msg; } finally { conn.Close(); } }
public override bool Delete(params object[] keys) { try { var provinceBo = new ProvinceBO(); var obj = provinceBo.Get(this.ConnectionHandler, keys); if (obj == null) { return(false); } var byFilter = new CityBO().Any(this.ConnectionHandler, x => x.ProvinceId == obj.Id); if (byFilter) { throw new Exception("این کشور دارای استان است آن را نمیتوانید حذف کنید"); } return(provinceBo.Delete(this.ConnectionHandler, keys)); } catch (KnownException ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public void Add(CityBO city) { if (city == null) { throw new ArgumentNullException("city"); } db.cityRepository.Add(city); unitofWork.Commit(); }
public HttpResponseMessage Put([FromBody] CityBO city) { bool result = DL.UpdateCity(city); if (result) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
// POST api/values public HttpResponseMessage Post([FromBody] CityBO city) { CityDL DL = new CityDL(); var cityKey = DL.InsertCity(city); if (cityKey != null && cityKey != Guid.Empty) { return(Request.CreateResponse(HttpStatusCode.OK, cityKey, Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public HttpResponseMessage GetDriverByID(string citykey) { CityBO cityBO = new CityBO(); cityBO = DL.GetCitybyKey(Guid.Parse(citykey)); if (cityBO != null) { return(Request.CreateResponse(HttpStatusCode.OK, cityBO, Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Not found", Configuration.Formatters.JsonFormatter)); } }
public List <CityBO> GetCity() { try { string sql = "dbo.fn_get_city"; List <CityBO> citylist = new List <CityBO>(); List <string> list = new List <string>(); conn = new NpgsqlConnection(connString); conn.Open(); using (var cmd = new NpgsqlCommand(sql, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; var reader = cmd.ExecuteReader(); do { while (reader.Read()) { var BO = new CityBO(); BO.citykey = Guid.Parse(reader["citykey"].ToString()); BO.cityid = Utils.CustomParse <string>(reader["cityid"]); BO.cityname = Utils.CustomParse <string>(reader["cityname"]); citylist.Add(BO); } }while (reader.NextResult()); reader.Close(); } return(citylist); } catch (Exception msg) { throw msg; } finally { conn.Close(); } }
public CityBO GetCitybyKey(Guid cityKey) { try { string sql = "dbo.fn_getcitybykey"; CityBO city = new CityBO(); conn = new NpgsqlConnection(connString); conn.Open(); using (var cmd = new NpgsqlCommand(sql, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("_citykey", NpgsqlTypes.NpgsqlDbType.Uuid, cityKey); var reader = cmd.ExecuteReader(); do { while (reader.Read()) { city.citykey = Guid.Parse(reader["citykey"].ToString()); city.cityid = Utils.CustomParse <string>(reader["cityid"]); city.cityname = Utils.CustomParse <string>(reader["cityname"]); } }while (reader.NextResult()); reader.Close(); } return(city); } catch (Exception msg) { throw msg; } finally { conn.Close(); } }
public bool UpdateCity(CityBO city) { try { string query = "dbo.fn_update_city"; conn = new NpgsqlConnection(connString); conn.Open(); NpgsqlTransaction tran = conn.BeginTransaction(); using (var cmd = new NpgsqlCommand(query, conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("_citykey", NpgsqlTypes.NpgsqlDbType.Uuid, city.citykey); cmd.Parameters.AddWithValue("_cityid", NpgsqlTypes.NpgsqlDbType.Varchar, city.cityid); cmd.Parameters.AddWithValue("_cityname", NpgsqlTypes.NpgsqlDbType.Varchar, city.cityname); var reader = cmd.ExecuteReader(); tran.Commit(); while (reader.Read()) { var result = bool.Parse(reader[0].ToString()); return(result); } reader.Close(); } return(false); } catch (Exception msg) { throw msg; } finally { conn.Close(); } }