Это мое действие, и у меня есть строго типизированное представление с почти 10+ выпадающими списками.Теперь ситуация для редактирования и листинга и новая во всех случаях, я должен предоставить значение для viewmodel.Мне нужны предложения о том, как я могу избежать такого повторения
public ActionResult Employees()
{
if (!ISValidLogin())
return RedirectToAction("Login", "Account");
EmployeeViewModel objEmpViewModel = new EmployeeViewModel();
objEmpViewModel.GetCampusByClientId = objGlobalRepo.GetCampusByClientId(Convert.ToInt32(Encrypt.GetUserCookieValue("ClientID")));
objEmpViewModel.GetBloodGroups = objGlobalRepo.GetBloodGroups();
objEmpViewModel.GetCategories = objGlobalRepo.GetCategoriesList();
objEmpViewModel.GetNationalities = objGlobalRepo.GetNationalities();
objEmpViewModel.GetOccupation = objGlobalRepo.GetOccupation();
objEmpViewModel.GetQualificationTypes = objGlobalRepo.GetQualificationTypes();
objEmpViewModel.GetRelation = objGlobalRepo.GetRelation();
objEmpViewModel.GetReligionsList = objGlobalRepo.GetReligionsList();
objEmpViewModel.GetCountries = objGlobalRepo.GetCountries();
objEmpViewModel.GetDepartments = objGlobalRepo.GetDepartments();
objEmpViewModel.GetDesignation = objGlobalRepo.GetDesignations();
objEmpViewModel.GetMaritalStatus = objGlobalRepo.GetMaritalStatus();
objEmpViewModel.GetRanks = objGlobalRepo.GetRanks();
objEmpViewModel.GetSpecialization = objGlobalRepo.GetSpecialization();
objEmpViewModel.GetTitlesList = objGlobalRepo.GetTitles();
objEmpViewModel.EmployeeInfo = new Employee();
objEmpViewModel.EmployeeList = objEmployeeRepo.EmployeeList();
objEmpViewModel.GuradiansDetails = new List<Guardian>();
objEmpViewModel.GuradiansDetails.Add(new Guardian());
objEmpViewModel.GetGender = objGlobalRepo.GetGender();
objEmpViewModel.GetEmployeeCategoriesList = objGlobalRepo.GetEmployeeCategoriesList();
ViewBag.Message = Convert.ToString(TempData["message"]);
TempData.Remove("message");
return View(objEmpViewModel);
}
[HttpPost]
public ActionResult Employees(EmployeeViewModel objEmpViewModel,HttpPostedFileBase file)
{
if (file != null)
{
string filename = FileUploads.SaveFile(file, Server.MapPath("~/Uploads/Employee/"));
objEmpViewModel.EmployeeInfo.ImageUrl = filename;
}
string result = objEmployeeRepo.AddEmployee(objEmpViewModel.EmployeeInfo, objEmpViewModel.GuradiansDetails);
objEmpViewModel.GetCampusByClientId = objGlobalRepo.GetCampusByClientId(Convert.ToInt32(Encrypt.GetUserCookieValue("ClientID")));
objEmpViewModel.GetBloodGroups = objGlobalRepo.GetBloodGroups();
objEmpViewModel.GetCategories = objGlobalRepo.GetCategoriesList();
objEmpViewModel.GetNationalities = objGlobalRepo.GetNationalities();
objEmpViewModel.GetOccupation = objGlobalRepo.GetOccupation();
objEmpViewModel.GetQualificationTypes = objGlobalRepo.GetQualificationTypes();
objEmpViewModel.GetRelation = objGlobalRepo.GetRelation();
objEmpViewModel.GetReligionsList = objGlobalRepo.GetReligionsList();
objEmpViewModel.GetCountries = objGlobalRepo.GetCountries();
objEmpViewModel.GetDepartments = objGlobalRepo.GetDepartments();
objEmpViewModel.GetDesignation = objGlobalRepo.GetDesignations();
objEmpViewModel.GetMaritalStatus = objGlobalRepo.GetMaritalStatus();
objEmpViewModel.GetRanks = objGlobalRepo.GetRanks();
objEmpViewModel.GetSpecialization = objGlobalRepo.GetSpecialization();
objEmpViewModel.GetTitlesList = objGlobalRepo.GetTitles();
objEmpViewModel.EmployeeList = objEmployeeRepo.EmployeeList();
objEmpViewModel.EmployeeInfo = new Employee();
objEmpViewModel.GuradiansDetails = new List<Guardian>();
objEmpViewModel.GuradiansDetails.Add(new Guardian());
objEmpViewModel.GetGender = objGlobalRepo.GetGender();
objEmpViewModel.GetEmployeeCategoriesList = objGlobalRepo.GetEmployeeCategoriesList();
TempData["message"] = "<div class='alert alert-success alert - dismissible fade in' role='alert'> <button type = 'button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span> </button> <strong>" + result + "</strong> </div>";
return View(objEmpViewModel);
}
Так что эти два метода имеют одну строку для заполнения свойств.По сути, я не хочу писать эти строки снова и снова.