public ActionResult Create(Company model) { if (!ModelState.IsValid) return View(model); Company.CreateCompany(model); return RedirectToAction("Index"); }
public static Company SearchCompany(string companyName) { using(var db = new ApplicationDbContext()) { Company company = new Company(); company = db.Companies.Where(x => x.CompanyName==companyName).SingleOrDefault(); return company; } }
//Metode public static void CreateCompany(Company company) { if (company != null) { using(var db=new ApplicationDbContext()) { //try //{ db.Companies.Add(company); db.SaveChanges(); //} //catch(Exception ex) when (ex is DbUpdateException || // ex is DbEntityValidationException || // ex is NotSupportedException || // ex is ObjectDisposedException || // ex is InvalidOperationException) //{ // ErrorHelpers.LogError(ex, ErrorLevel.Error, "Error on write in database"); //} } } }
//POST: Edit public static void EditCompany(Company c) { using (var db = new ApplicationDbContext()) { //try //{ db.Entry(c).State = EntityState.Modified; db.SaveChanges(); //} //catch (Exception ex) when (ex is DbUpdateException || // ex is DbEntityValidationException || // ex is NotSupportedException || // ex is ObjectDisposedException || // ex is InvalidOperationException) //{ // ErrorHelpers.LogError(ex, ErrorLevel.Error, "Error on write in database"); //} } }