protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
public Employee AddUpdate(Employee objEmp) { Employee Result = new Employee(); if (objEmp.Id != 0) { try { tempdbEntities objdb = new tempdbEntities(); var empData = objdb.Emps.Where(x => x.Id == objEmp.Id).FirstOrDefault(); if (empData != null) { empData.Name = objEmp.Name; empData.City = objEmp.City; objdb.SaveChanges(); objdb.Dispose(); Result.Status = true; Result.mesage = "success"; } else { Result.Status = false; Result.mesage = "no record found"; } } catch (Exception) { Result.Status = true; Result.mesage = "success"; } } else { try { tempdbEntities objdb = new tempdbEntities(); Emp objemployee = new Emp(); objemployee.Name = objEmp.Name; objemployee.City = objEmp.City; objdb.Emps.Add(objemployee); objdb.SaveChanges(); objdb.Dispose(); Result.Status = true; Result.mesage = "success"; } catch (Exception) { Result.Status = false; Result.mesage = "Falied"; } } return(Result); }