public async Task <IActionResult> Create() { SysDepartmentViewModel model = new SysDepartmentViewModel(); model.ParentList = await _departmentService.GetDepartmentTree(); return(View(model)); }
public async Task <SysDepartmentViewModel> UpdateSysDeparment(SysDepartmentViewModel model) { var entity = model.ToEntity(); entity.DepartmentId = model.Id; _repository.Update(entity); await _context.SaveChangesAsync(); return(model); }
public async Task <IActionResult> Edit(SysDepartmentViewModel model) { try { await _departmentService.UpdateSysDeparment(model); return(RedirectToAction("Index")); } catch (Exception) { throw; } return(View(model)); }
public async Task <IActionResult> Create(SysDepartmentViewModel model) { try { await _departmentService.SaveSysDepartment(model); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(model)); } return(View(model)); }
public async Task <SysDepartmentViewModel> SaveSysDepartment(SysDepartmentViewModel model) { var entity = model.ToEntity(); entity.DepartmentId = SequenceQueue.NewIdString(""); entity.State = 0; entity.ParentId = model.ParentId; entity.DepartmentName = model.DepartmentName; model.Id = entity.DepartmentId; await _repository.AddAsync(entity); await _context.SaveChangesAsync(); return(model); }
public static SysDepartment ToEntity(this SysDepartmentViewModel model) { return(model.MapTo <SysDepartmentViewModel, SysDepartment>()); }