public ActionResult Create() { var model = new SucKhoeEditViewModel(); PrepareEdit(model); return(this.View(model)); }
public void PrepareEdit(SucKhoeEditViewModel model) { //thong tin ca nhan service var TTCNSerice = this.Service <IThongTinCaNhanService>(); model.AvailableIDs = TTCNSerice.Get() .Where(q => q.Active == true) .Select(q => new SelectListItem() { Selected = false, Text = q.HoTen, Value = q.Id.ToString(), }); }
public async Task <ActionResult> Create(SucKhoeEditViewModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var service = this.Service <ISucKhoeService>(); try { var entity = model.ToEntity(); await service.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(this.RedirectToAction("Index")); }
public async Task <JsonResult> Edit(SucKhoeEditViewModel model) { var service = this.Service <ISucKhoeService>(); if (!this.ModelState.IsValid) { return(Json(new { success = false, message = "Có lỗi xảy ra, vui lòng kiểm tra lại." })); } try { var entity = model.ToEntity(); await service.UpdateAsync(entity); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); var result = await new SystemLogController().Create("Sửa", controllerName, entity.Id); } catch (Exception e) { Console.WriteLine(e); return(Json(new { success = false, message = "Có lỗi xảy ra, vui lòng thử lại." })); } return(Json(new { success = true, message = "Cập nhật thành công." })); }