public int UpdateEmployee(EmpInfo em) { int RetVal = 0; int Id = em.EmpId; var Updated = (from p in Main.employees where p.empid == Id select p).First(); employee obj = new employee(); project pro = new project(); pro.projId = em.ProjectId; pro.projname = em.ProjectName; Updated.empid = em.EmpId; Updated.empname = em.EmpName; Updated.empsalary = em.EmpSalary; Updated.empAddress = em.EmpAddress; Updated.project = pro; Main.employees.Attach(Updated); Main.Entry(Updated).State = System.Data.Entity.EntityState.Modified; Main.SaveChanges(); var Table = (from Emp in Main.employees where Emp.empname == em.EmpName select Emp.empid).First(); if (Table == em.EmpId) { RetVal = 1; } else { RetVal = 0; } return(RetVal); }
public int InsertEmployee(EmpInfo emp) { int t = 0; var beforeCount = (from i in Main.employees select i).Count(); employee obj = new employee(); project pro = new project(); pro.projId = emp.ProjectId; pro.projname = emp.ProjectName; obj.empid = emp.EmpId; obj.empname = emp.EmpName; obj.empsalary = emp.EmpSalary; obj.empAddress = emp.EmpAddress; obj.project = pro; Main.employees.Add(obj); Main.SaveChanges(); var afterCount = (from i in Main.employees select i).Count(); if (afterCount > beforeCount) { t = 1; } else if (afterCount == beforeCount) { t = 0; } else { t = 2; } return(t); }
public int UpdateProjec(project pr) { int Id = pr.projId; int res = 0; var Updated = (from p in Main.projects where p.projId == Id select p).First(); Updated.projId = pr.projId; Updated.projname = pr.projname; Main.projects.Attach(Updated); Main.Entry(Updated).State = System.Data.Entity.EntityState.Modified; Main.SaveChanges(); if (Updated.projname == pr.projname) { res = 1; } else { res = 0; } return(res); }