public DepartmentFormModel GetDepartmentFormData(BaseViewModel arg) { ICountryService scon; IBranchService sbrn; //IDivisionService sdiv; IUnitOfWork uwork = new UnitOfWork(); DepartmentFormModel model = new DepartmentFormModel(); scon = new CountryService(new CountryRepository(uwork)); sbrn = new BranchService(new BranchRepository(uwork)); //sdiv = new DivisionService(new DivisionRepository(uwork)); try { model.countryList = scon.GetAllCountryList(arg); model.branchList = sbrn.GetAllBranchList(arg); // model.divisionList = sdiv.GetDivisionList(arg); } catch (Exception ex) { model = null; IErrorLogService errorLog = new ErrorLogService(); string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; errorLog.SetErrorLog(arg.CurrentUserID, "Department", message); throw new Exception(ex.Message); } return(model); }
public ActionResult Create(DepartmentFormModel model) { if (ModelState.IsValid) { var item = Mapper.Map <DepartmentFormModel, Department>(model); GetSession.Save(item); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Edit(DepartmentFormModel model) { var item = GetSession.Get <Department>(model.Id); if (ModelState.IsValid) { Mapper.Map <DepartmentFormModel, Department>(model, item); GetSession.Update(item); return(RedirectToAction("Index")); } return(View(model)); }
public void UpdateDepartments() { var excel = new ExcelQueryFactory(); string[] ex_names = MvcApplication.Config("excel_name").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int ex_name = 0; ex_name < ex_names.Length; ex_name++) { excel.FileName = ex_names[ex_name]; var result_employees = from c in excel.WorksheetNoHeader(0) select c; List <Department> existing_deps = (List <Department>)GetSession.QueryOver <Department>().List(); List <string> existing_dep_list = new List <string>(); foreach (var dep in existing_deps) { if (!existing_dep_list.Contains(dep.Name)) { existing_dep_list.Add(dep.Name); } } foreach (var new_dep in result_employees) { if (!string.IsNullOrEmpty(new_dep[4].ToString().Trim()) && !existing_dep_list.Contains(new_dep[4].ToString().Trim())) { DepartmentFormModel model = new DepartmentFormModel() { Name = new_dep[4].ToString().Trim() }; var item = Mapper.Map <DepartmentFormModel, Department>(model); GetSession.Save(item); existing_dep_list.Add(new_dep[4].ToString().Trim()); } } } }
public ActionResult Create() { var model = new DepartmentFormModel(); return(View(model)); }