public IActionResult Index(int ContractId) { ContractVisaViewModel visa = new ContractVisaViewModel(); visa.ContractId = ContractId; var contractVisaList = _visa.GetContractVisas().Where(x => x.ContractId == ContractId); ViewBag.ContractVisa = contractVisaList; ViewBag.EmployeeId = new SelectList(_employee.GetEmployees(), "Id", "FirstName"); return(View(visa)); }
public IActionResult Add(ContractVisaViewModel visaViewModel) { visaViewModel.VisaByName = User.Identity.Name; var visitbyid = _user.GetUserByName(visaViewModel.VisaByName); visaViewModel.VisaById = visitbyid.Id; var contractVisaList = _visa.GetContractVisas().Where(x => x.ContractId == visaViewModel.ContractId); ViewBag.ContractVisa = contractVisaList; ViewBag.EmployeeId = new SelectList(_employee.GetEmployees().Where(x => x.EmployeeStatusId == (int)EnumHelper.EmployeeStatus.New), "Id", "FirstName", visaViewModel.EmployeeId); if (visaViewModel.EmployeeId == null) { ModelState.AddModelError("", "الرجاء تحدد الموظف"); } if (visaViewModel.Id == 0) { ModelState.Remove("Id"); ModelState.Remove("EmployeeId"); if (ModelState.IsValid) { var visacontract = _mapper.Map <ContractVisa>(visaViewModel); _visa.AddContractVisa(visacontract); _toastNotification.AddSuccessToastMessage("تم التفيز بنجاح"); return(RedirectToAction(nameof(Index), new { ContractId = visaViewModel.ContractId })); } return(View(nameof(Index), visaViewModel)); } else { ModelState.Remove("EmployeeId"); if (ModelState.IsValid) { var visacontract = _mapper.Map <ContractVisa>(visaViewModel); _visa.UpdateContractVisa(visaViewModel.Id, visacontract); _toastNotification.AddSuccessToastMessage("تم تعديل التفيز بنجاح"); return(RedirectToAction(nameof(Index), new { ContractId = visaViewModel.ContractId })); } return(View(nameof(Index), visaViewModel)); } }