public IEnumerable <ViewContracts> GetContracts() { List <Contract> contracts = db.Contracts.Include(data => data.Supply).Include(data => data.Employe).ToList(); List <ViewContracts> viewContracts = new List <ViewContracts>(); foreach (var contract in contracts) { int id; ViewContracts bufferContract = new ViewContracts() { Id = contract.Id }; try { bufferContract.EmployeId = contract.Employe.EmployeId; } catch { } try { bufferContract.SupplyId = contract.Supply.SupplyId; } catch { } viewContracts.Add(bufferContract); } return(viewContracts); }
public void AddContract(ViewContracts contract) { Contract _contract = new Contract(); db.Contracts.Add(_contract); db.SaveChanges(); }
public void AddContractEmployeLink(GetContractEmploye link) { Employe defaultEmploye = db.Employers.Include(data => data.Contracts).FirstOrDefault(data => data.Id == link.EmployeId); ViewContracts contract = new ViewContracts(); this.AddContract(contract); db.SaveChanges(); Contract defaultContract = db.Contracts.Include(data => data.Employe).Include(data => data.Supply).Last(); ContractsEmploye CE = new ContractsEmploye() { ContractId = defaultContract.Id, EmployeId = link.EmployeId }; defaultEmploye.Contracts.Add(CE); db.Entry(defaultEmploye).State = EntityState.Modified; db.SaveChanges(); }