示例#1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
示例#2
0
文件: Employee.cs 项目: ds210083/test
        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);
        }