public async Task <ActionResult> Edit(int idktx) { var kyTucXaService = this.Service <IKyTucXaService>(); var model = new KyTucXaEditViewModel(await kyTucXaService.GetAsync(idktx)); return(View(model)); }
public async Task <ActionResult> Edit(KyTucXaEditViewModel model) { try { if (!this.ModelState.IsValid) { return(View(model)); } var kyTucXaService = this.Service <IKyTucXaService>(); var thongTinCaNhanService = this.Service <IThongTinCaNhanService>(); var entity = await kyTucXaService.GetAsync(model.Id); model.CopyToEntity(entity); entity.Active = true; entity.IdThongTinCaNhan = model.IdThongTinCaNhan; entity.ThongTinCaNhan = await thongTinCaNhanService.GetAsync(entity.IdThongTinCaNhan); await kyTucXaService.UpdateAsync(entity); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); var result = await new SystemLogController().Create("Sửa", controllerName, entity.Id); return(RedirectToAction("Index")); } catch (Exception e) { return(RedirectToAction("Index")); } }
public ActionResult Create() { var thongTinCaNhanService = this.Service <IThongTinCaNhanService>(); var model = new KyTucXaEditViewModel(); model.AvailableThongTinCaNhan = thongTinCaNhanService.GetActive().Select(q => new SelectListItem() { Text = q.HoTen + "[CMND: " + q.CMND + "]", Value = q.Id.ToString(), Selected = false, }); return(View(model)); }
public async Task <ActionResult> Create(KyTucXaEditViewModel model) { if (!this.ModelState.IsValid) { return(View(model)); } try { var kyTucXaService = this.Service <IKyTucXaService>(); model.Active = true; var entity = model.ToEntity(); await kyTucXaService.CreateAsync(entity); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); var result = await new SystemLogController().Create("Tạo", controllerName, entity.Id); } catch (Exception e) { Console.WriteLine(e); } return(RedirectToAction("Index")); }