public bool updateCompany(CompanyDetailBO company) { try { string sql = "dbo.fn_update_company"; connection = new NpgsqlConnection(connString); connection.Open(); NpgsqlTransaction tran = connection.BeginTransaction(); using (var cmd = new NpgsqlCommand(sql, connection)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("_compkey", NpgsqlTypes.NpgsqlDbType.Uuid, company.compkey); cmd.Parameters.AddWithValue("_compid", NpgsqlTypes.NpgsqlDbType.Varchar, company.compid); cmd.Parameters.AddWithValue("_compname", NpgsqlTypes.NpgsqlDbType.Varchar, company.compname); //cmd.Parameters.AddWithValue("_addrkey", NpgsqlTypes.NpgsqlDbType.Uuid, company.addrkey); var compKey = cmd.ExecuteNonQuery(); tran.Commit(); } return(true); } catch (Exception msg) { throw msg; } finally { connection.Close(); } }
public HttpResponseMessage GetCompanyByID(string compkey) { CompanyDetailBO customer = DL.GetCompanyDetailsbykey(Guid.Parse(compkey)); if (customer != null) { var address = new AddressDL().GetAddressByKey(customer.addrkey); customer.Address = new AddressBO() { AddrKey = address.AddrKey, Address1 = address.Address1, Address2 = address.Address2, City = address.City, State = address.State, Zip = address.Zip, Email = address.Email, Phone = address.Phone, Fax = address.Fax, Country = address.Country, Website = address.Website, Phone2 = address.Phone2, Email2 = address.Email2 }; return(Request.CreateResponse(HttpStatusCode.OK, customer, Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Not found", Configuration.Formatters.JsonFormatter)); } }
public HttpResponseMessage Put([FromBody] CompanyDetailBO company) { if (company.Address != null) { AddressDL addr = new AddressDL(); bool updated = addr.UpdateAddress(company.Address); } bool result = DL.updateCompany(company); if (result) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public List <CompanyDetailBO> GetCompanies() { try { string sql = "dbo.fn_getcompanies"; List <CompanyDetailBO> companieslist = new List <CompanyDetailBO>(); List <string> list = new List <string>(); connection = new NpgsqlConnection(connString); connection.Open(); using (var cmd = new NpgsqlCommand(sql, connection)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; var reader = cmd.ExecuteReader(); do { while (reader.Read()) { var company = new CompanyDetailBO(); company.compkey = Utils.CustomParse <Guid>(reader["compkey"]); company.compid = Utils.CustomParse <string>(reader["compid"]); company.compname = Utils.CustomParse <string>(reader["compname"]); company.addrkey = Utils.CustomParse <Guid>(reader["addrkey"]); companieslist.Add(company); } }while (reader.NextResult()); reader.Close(); } return(companieslist); } catch (Exception msg) { throw msg; } finally { connection.Close(); } }
public HttpResponseMessage Post([FromBody] CompanyDetailBO company) { AddressDL addr = new AddressDL(); if (company.Address != null) { var addrkey = new AddressDL().InsertAddress(company.Address); company.addrkey = addrkey; } var compkey = DL.insertCompany(company); // Guid custkey =repo.Add(_customer); if (compkey != null && compkey != Guid.Empty) { return(Request.CreateResponse(HttpStatusCode.OK, compkey, Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public CompanyDetailBO GetCompanyDetailsbykey(Guid compKey) { try { string sql = "dbo.fn_getcompanydetailbykey"; CompanyDetailBO company = new CompanyDetailBO(); connection = new NpgsqlConnection(connString); connection.Open(); using (var cmd = new NpgsqlCommand(sql, connection)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("_compkey", NpgsqlTypes.NpgsqlDbType.Uuid, compKey); var reader = cmd.ExecuteReader(); do { while (reader.Read()) { company.compkey = Utils.CustomParse <Guid>(reader["compkey"]); company.compid = Utils.CustomParse <string>(reader["compid"]); company.compname = Utils.CustomParse <string>(reader["compname"]); company.addrkey = Utils.CustomParse <Guid>(reader["addrkey"]); } }while (reader.NextResult()); reader.Close(); } return(company); } catch (Exception msg) { throw msg; } finally { connection.Close(); } }
public HttpResponseMessage GetCompanies() { List <CompanyDetailBO> company = DL.GetCompanies(); List <CompanyDetailBO> companyBOList = new List <CompanyDetailBO>(); if (company.Count > 0) { foreach (var comp in company) { CompanyDetailBO companyBO = new CompanyDetailBO(); companyBO.compkey = comp.compkey; companyBO.compid = comp.compid; companyBO.compname = comp.compname; var address = new AddressRepository().GetbyId(comp.addrkey); companyBO.Address = new AddressBO() { AddrKey = address.addrkey, Address1 = address.address1, Address2 = address.address2, City = address.city, State = address.state, Zip = address.zipcode, Email = address.email, Phone = address.phone, Fax = address.fax, Website = address.website }; companyBOList.Add(companyBO); } return(Request.CreateResponse(HttpStatusCode.OK, companyBOList, Configuration.Formatters.JsonFormatter)); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Not found", Configuration.Formatters.JsonFormatter)); } }