public ActionResult Create(TEmployee emp) { db.TEmployee.Add(emp); db.SaveChanges(); return(RedirectToAction("Index", new { depId = emp.FDepId })); }
public async Task <List <Employee> > FindAll() { var result = await TEmployee.Join( THuman, emp => emp.HumanId, hum => hum.Id, (emp, hum) => new { emp.EmployeeId, hum.Id, hum.FirstName, hum.LastName, hum.Sex, hum.Birthday, emp.MailAddress } ).ToArrayAsync(); List <Employee> emps = new List <Employee>(); foreach (var item in result) { emps.Add( new Employee( employeeId: new EmployeeId(item.EmployeeId), email: new Email(item.MailAddress), employeeAttr: new Human( humanId: new HumanId(item.Id), fullName: new FullName(item.FirstName, item.LastName), birthday: new Birthday(item.Birthday), sex: new Sex(item.Sex), relationship: new Relationship("0") //TODO ) ) ); } return(emps); }
public IActionResult SaveEmpoyee([FromBody] TEmployee empl) { if (ModelState.IsValid) { var compId = int.Parse(User.FindFirst(x => x.Type == "CompanyId").Value); if (empl.Id == 0) { var employee = empl.Adapt <Users>(); employee.CompanyId = compId; _db.Users.Add(employee); try { _db.SaveChanges(); } catch (DbUpdateException ex) { return(Json("Не повторять иин и логин \n" + ex.InnerException.Message)); } } else { var employee = _db.Users.Find(empl.Id); employee = empl.Adapt(employee); _db.SaveChanges(); } return(Json(true)); } else { return(Json("Данные имеют неверный формат")); } }
private async Task <int> SaveEmployee(Employee employee) { var tEmp = this.TEmployee.FirstOrDefault(e => e.EmployeeId == employee.EmployeeId.Value); if (tEmp == null) { tEmp = new TEmployee(); this.TEmployee.Add(tEmp); } tEmp.EmployeeId = employee.EmployeeId.Value; tEmp.MailAddress = employee.Email.Value; tEmp.HumanId = employee.EmployeeAttr.HumanId.Value; var tHum = this.THuman.FirstOrDefault(e => e.Id == tEmp.HumanId); if (tHum == null) { tHum = new THuman(); this.THuman.Add(tHum); } tHum.Id = employee.EmployeeAttr.HumanId.Value; tHum.FirstName = employee.FirstName; tHum.LastName = employee.LastName; tHum.Sex = employee.Sex; tHum.Birthday = employee.Birthday; return(0); }
public ActionResult DeleteConfirmed(int id) { TEmployee tEmployee = db.TEmployees.Find(id); db.TEmployees.Remove(tEmployee); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "intEmployeeID,strFirstName,strLastName,intJobTitleID,intUserID")] TEmployee tEmployee) { if (ModelState.IsValid) { db.Entry(tEmployee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.intJobTitleID = new SelectList(db.TJobTitles, "intJobTitleID ", "strJobTitleDesc", tEmployee.intJobTitleID); return(View(tEmployee)); }
// GET: TEmployees/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TEmployee tEmployee = db.TEmployees.Find(id); if (tEmployee == null) { return(HttpNotFound()); } return(View(tEmployee)); }
// GET: TEmployees/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TEmployee tEmployee = db.TEmployees.Find(id); if (tEmployee == null) { return(HttpNotFound()); } ViewBag.intJobTitleID = new SelectList(db.TJobTitles, "intJobTitleID ", "strJobTitleDesc", tEmployee.intJobTitleID); return(View(tEmployee)); }
public ActionResult Create([Bind(Include = "intEmployeeID,strFirstName,strLastName,intJobTitleID")] TEmployee tEmployee) { if (ModelState.IsValid) { //db.TEmployees.Add(tEmployee); //db.SaveChanges(); SqlParameter[] param = new SqlParameter[] { new SqlParameter("@strFirstName", tEmployee.strFirstName), new SqlParameter("@strLastName", tEmployee.strLastName), new SqlParameter("@intJobTitleID", tEmployee.intJobTitleID) }; db.Database.ExecuteSqlCommand("uspAddUserEmployee @strFirstName, @strLastName, @intJobTitleID", param); return(RedirectToAction("Index")); } ViewBag.intJobTitleID = new SelectList(db.TJobTitles, "intJobTitleID ", "strJobTitleDesc", tEmployee.intJobTitleID); return(View(tEmployee)); }
public Node(Node next, TEmployee data) { Next = next; Data = data; }
public Node(TEmployee employee) { Next = null; Data = employee; }
public async Task <Employee> FindByAsync(string employeeId) { var query = TEmployee .Join(THuman, emp => emp.HumanId, hum => hum.Id, (emp, hum) => new { emp.EmployeeId, emp.MailAddress, emp.HumanId, hum.FirstName, hum.LastName, hum.Sex, hum.Birthday, } ) .GroupJoin(TFamily, rt => rt.EmployeeId, lt => lt.EmployeeId, (emp, family) => new { emp, family }).SelectMany( x => x.family.DefaultIfEmpty(), (x, fam) => new { x.emp, x.family, fam.HumanId, fam.EmployeeId, fam.RelationShip } ) .GroupJoin(THuman, x => x.HumanId, Human => Human.Id, (j2, family) => new { j2, family } ).SelectMany( x => x.family.DefaultIfEmpty(), (x, fam) => new { x.j2.emp.EmployeeId, x.j2.emp.MailAddress, x.j2.emp.HumanId, x.j2.emp.FirstName, x.j2.emp.LastName, x.j2.emp.Birthday, x.j2.emp.Sex, //x.j2.emp., famliyId = fam.Id, family_FirstName = fam.FirstName, family_LastName = fam.LastName, family_Sex = fam.Sex, family_Birthday = fam.Birthday, } ) .Where(e => e.EmployeeId == employeeId); var res = await query.ToArrayAsync(); if (res.Count() == 0) { return(null); } var employee = new Employee( employeeId: new EmployeeId(res[0].EmployeeId), email: new Email(res[0].MailAddress), employeeAttr: new Human( new HumanId(res[0].HumanId), new FullName(res[0].FirstName, res[0].LastName), new Sex(res[0].Sex), new Birthday(res[0].Birthday), new Relationship("0") ) ); res.ToList().ForEach(e => employee.Append(new Human( new HumanId(e.famliyId), new FullName(e.family_FirstName, e.family_LastName), new Sex(e.family_Sex), new Birthday(e.family_Birthday), new Relationship("1") //TODO )) ); return(employee); }