Example #1
0
        public async Task <ActionResult> Details(int?id, EmployeeExtendData employeeEx)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (ModelState.IsValid && employeeEx.Contract.StartDate != null && employeeEx.Contract.EndDate != null &&
                employeeEx.Contract.Type != null && employeeEx.Contract.Salary != null)
            {
                employeeEx.Contract.EmployeeID = (int)id;
                db.Contracts.Add(employeeEx.Contract);
                await db.SaveChangesAsync();

//                return RedirectToAction("Details", id);
            }

/*
 *          employeeEx.Employee = db.Employees.Include(e => e.Resign)
 *              .Where(e => e.ID == id)
 *              .Include(e => e.Contracts.Select(c => c.Employee))
 *              .Include(e => e.Personnels.Select(p => p.Employee))
 *              .Single();
 *
 *          return View(employeeEx);*/
            return(RedirectToAction("Details", id));
        }
Example #2
0
        // GET: Employee/Details/5
        public async Task <ActionResult> Details(int?id, int?contractsID)
        {
            if (Session["LoginUserID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (contractsID != null)
            {
                Contract contract = await db.Contracts.FindAsync(contractsID);

                if (contract != null)
                {
                    //                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                    try
                    {
                        //                db.Entry(employee).State = EntityState.Deleted;
                        db.Contracts.Remove(contract);

                        await db.SaveChangesAsync();

                        //                return RedirectToAction("Details", id);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        return(RedirectToAction("Details", id));
                        //                return RedirectToAction("Delete", new { concurrencyError = true, id = employee.ID });
                    }
                    catch (DataException /* dex */)
                    {
                        //Log the error (uncomment dex variable name after DataException and add a line here to write a log.
                        ModelState.AddModelError(string.Empty, "Unable to delete. Try again, and if the problem persists contact your system administrator.");
                        return(RedirectToAction("Details", id));
                        //                return View(employee);
                    }
                }
            }

            //            Employee employee = await db.Employees.FindAsync(id);
            var employee = new EmployeeExtendData();

            employee.Employee = db.Employees.Include(e => e.Resign)
                                .Where(e => e.ID == id)
                                .Include(e => e.Contracts.Select(c => c.Employee))
                                .Include(e => e.Personnels.Select(p => p.Employee))
                                .Single();

            employee.Employee.Personnels = employee.Employee.Personnels.OrderBy(p => p.StartDate).ToList();
            employee.Employee.Contracts  = employee.Employee.Contracts.OrderBy(c => c.StartDate).ToList();

            if (employee.Employee == null)
            {
                return(HttpNotFound());
            }

            return(View(employee));
        }