public async Task <IActionResult> PutBestPractice(int id, [FromBody] BestPractice bp) { if (id != bp.BestPracticeId) { return(BadRequest()); } db.Entry(bp).State = EntityState.Modified; string[] comps = removeChars(bp.Company).Split(","); BestPracticeCompanyController bpc_cont = new BestPracticeCompanyController(db); await bpc_cont.DeleteBestPracticeCompany(id); // addCompanies addCompanies(id, comps); // IList<Company> companyList = new List<Company>(); // for(int i = 0; i< comps.Count(); i++) { // companyList.Add(db.Company.Where(entity => entity.Name.Equals(comps[i], StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault()); // } // for(int i = 0; i < companyList.Count(); i++) { // db.BestPracticeCompany.Add(new BestPracticeCompany{ // BestPracticeId = id, // CompanyId = companyList[i].CompanyId // }); // } await db.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <BestPractice> > PostBestPractice([FromBody] BestPractice bp) { string[] comps = removeChars(bp.Company).Split(","); string dept = removeChars(bp.Department); bp.Department = dept; db.BestPractice.Add(bp); int id = bp.BestPracticeId; // addCompanies IList <Company> companyList = new List <Company>(); for (int i = 0; i < comps.Count(); i++) { companyList.Add(db.Company.Where(entity => entity.Name.Equals(comps[i], StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault()); } for (int i = 0; i < companyList.Count(); i++) { db.BestPracticeCompany.Add(new BestPracticeCompany { BestPracticeId = id, CompanyId = companyList[i].CompanyId }); } await db.SaveChangesAsync(); return(CreatedAtAction(nameof(GetBestPractice), new { id }, bp)); }
static void Main(string[] args) { Console.WriteLine("--------------------"); Console.WriteLine("Running Bad Practice"); BadPractice badPractice = new BadPractice(); badPractice.Run(); Console.WriteLine("--------------------"); Console.WriteLine("--------------------"); Console.WriteLine("Running Best Practice"); BestPractice bestPractice = new BestPractice(); bestPractice.Run(); Console.WriteLine("--------------------"); }