Ejemplo n.º 1
0
        public JsonResult EditEmployee(int id)
        {
            string status = "";
            EmployeeIndexViewModel employee = null;
            Employee dbEmployee             = _db.Employees.Find(id);

            if (dbEmployee != null)
            {
                employee = new EmployeeIndexViewModel
                {
                    Id             = dbEmployee.Id,
                    FirstName      = dbEmployee.FirstName,
                    LastName       = dbEmployee.LastName,
                    Designation    = dbEmployee.Designation,
                    JoinDate       = dbEmployee.JoinDate,
                    CurrentSalary  = dbEmployee.CurrentSalary,
                    Department     = dbEmployee.Department,
                    NextReviewDate = dbEmployee.NextReviewDate,
                    DateOfBirth    = dbEmployee.DateOfBirth,
                    Gender         = dbEmployee.Gender
                };
            }
            else
            {
                status = "No Employee Found!";
            }

            return(Json(new { employee = employee, status = status }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Edit(Employee model)
        {
            string status = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var employee = await _db.Employees.FindAsync(model.Id);

                    if (employee != null)
                    {
                        employee.FirstName      = model.FirstName;
                        employee.LastName       = model.LastName;
                        employee.JoinDate       = model.JoinDate;
                        employee.CurrentSalary  = model.CurrentSalary;
                        employee.Designation    = model.Designation;
                        employee.Department     = model.Department;
                        employee.NextReviewDate = model.NextReviewDate;
                        employee.DateOfBirth    = model.DateOfBirth;
                        employee.Gender         = model.Gender;

                        status = "Success";
                    }
                    else
                    {
                        status = "Something went wrong";
                    }
                    await _db.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                status = "Invalid Input";
            }


            return(Json(new
            {
                status = status
            }));
        }
Ejemplo n.º 3
0
        public async Task <JsonResult> Create(EmployeeFormViewModel viewModel)
        {
            string status = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var model = new Employee()
                    {
                        FirstName      = viewModel.FirstName,
                        LastName       = viewModel.LastName,
                        JoinDate       = viewModel.JoinDate,
                        CurrentSalary  = viewModel.CurrentSalary,
                        Designation    = viewModel.Designation,
                        Department     = viewModel.Department,
                        NextReviewDate = viewModel.NextReviewDate,
                        DateOfBirth    = viewModel.DateOfBirth,
                        Gender         = viewModel.Gender
                    };

                    _db.Employees.Add(model);
                    await _db.SaveChangesAsync();

                    status = "Success";
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                status = "Invalid Input";
            }
            return(Json(new { status = status }));
        }
        public async Task <JsonResult> Create(Employee model)
        {
            string status = "";

            if (ModelState.IsValid)
            {
                try
                {
                    _db.Employees.Add(model);
                    await _db.SaveChangesAsync();

                    status = "Success";
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                status = "Invalid Input";
            }
            return(Json(new { status = status }));
        }