public ActionResult MapEmployeesToClientNew()
        {
            MapEmployeesToClientFormViewModel viewModel = new MapEmployeesToClientFormViewModel
            {
                Title     = "Map Employee to Client",
                Employees = _context.Employees.ToList()
            };

            return(View("MapEmployeeToClientForm", viewModel));
        }
        public ActionResult MapEmployeesToClientEdit(int id)
        {
            ClientEmployeesMapping mappingInDb = _context.ClientEmployeesMapping.Where(x => x.client_employee_map_id == id).FirstOrDefault();

            if (mappingInDb == null)
            {
                ModelState.AddModelError("", "Not found.");
                return(View("MapEmployeeToClientForm", mappingInDb));
            }

            MapEmployeesToClientFormViewModel viewModel = new MapEmployeesToClientFormViewModel
            {
                employee_id = mappingInDb.employee_id,
                client_id   = int.Parse(Session["ClientId"].ToString()),
                Title       = "Tearms Condition Edit",
                Employees   = _context.Employees.ToList()
            };

            return(View("MapEmployeeToClientForm", viewModel));
        }
        public ActionResult MapEmployeesToClientSave(MapEmployeesToClientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("MapEmployeeToClientForm", viewModel));
            }

            if (viewModel.client_employee_map_id == 0)
            {
                ClientEmployeesMapping mapping = new ClientEmployeesMapping
                {
                    employee_id = viewModel.employee_id,
                    created_on  = DateTime.Now,
                    is_active   = true,
                    client_id   = int.Parse(Session["ClientId"].ToString())
                };

                _context.ClientEmployeesMapping.Add(mapping);
                _context.SaveChanges();
            }
            else
            {
                ClientEmployeesMapping mappingInDb = _context.ClientEmployeesMapping.Where(x => x.client_employee_map_id == viewModel.client_employee_map_id).FirstOrDefault();

                if (mappingInDb == null)
                {
                    ModelState.AddModelError("", "Bad request.");
                    return(View("MapEmployeeToClientForm", viewModel));
                }

                mappingInDb.employee_id = viewModel.employee_id;

                _context.Entry(mappingInDb).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
            }

            return(RedirectToAction("MapEmployeesToClientIndex",
                                    new { client_id = int.Parse(Session["ClientId"].ToString()) }));
        }