public async Task <IActionResult> Edit(DefaultModel model, ModSubjectEntity item) { ViewBag.Title = "Cập nhật thông tin"; if (string.IsNullOrEmpty(model.ID) && string.IsNullOrEmpty(item.ID)) { SetMessageWarning("Chưa chọn đối tượng chỉnh sửa"); } else { string ID = !string.IsNullOrEmpty(model.ID) ? model.ID : item.ID; var _item = _service.GetByID(ID); if (string.IsNullOrEmpty(item.Name)) { _item.Name = item.Name; _item.Updated = DateTime.Now; } //TODO: tính toán xem có cần cập nhật lại code ko _item.IsActive = item.IsActive; await _service.AddAsync(_item); ViewBag.Data = _service.GetByID(ID); SetMessageSuccess("Cập nhật thành công"); } ViewBag.Model = model; return(RedirectToAction("index")); }
public async Task <IActionResult> Create(DefaultModel model, ModSubjectEntity item) { ViewBag.Title = "Thêm mới"; if (!string.IsNullOrEmpty(model.ID) || !string.IsNullOrEmpty(item.ID)) { return(RedirectToAction("Edit", new { model.ID })); } else { if (string.IsNullOrEmpty(item.Name)) { SetMessageWarning("Bạn chưa điện tên môn học"); return(View()); } else { item.Code = UnicodeName.ConvertUnicodeToCode(item.Name, "-", true); item.Created = DateTime.Now; item.Updated = DateTime.Now; item.IsAdmin = true; item.CreateUser = _currentUser.ID; if (_service.GetItemByCode(item.Code) == null) { await _service.AddAsync(item); SetMessageSuccess("Thêm mới thành công"); return(RedirectToAction("Index")); } else { SetMessageWarning("Môn học đã tồn tại"); return(View()); } } } }