public async Task <IActionResult> Edit(BulletinEditViewModel webModel) { if (ModelState.IsValid) { bool flag; if (string.IsNullOrEmpty(webModel.Id)) { //Add Bulletin flag = await _service.InsertBulletinAsync(webModel, _context); } else { //Update Bulletin flag = await _service.UpdateBulletinAsync(webModel, _context); } return(Json(new { success = flag, msg = flag ? "公告信息编辑成功" : "公告信息编辑失败" })); } return(Json(new { success = false, msg = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors).FirstOrDefault().ErrorMessage })); }
public IActionResult Detail(string bullet_id) { string language_id = CultureInfo.CurrentCulture.Name; BulletinEditViewModel bulletin = _bulletinService.GetBulletinDetail(bullet_id, language_id, out string resultCode); if (bulletin == null) { string errorCode = _localizer[resultCode].Value; } return(View(bulletin)); }
public IActionResult Edit(string bullet_id) { string language_id = CultureInfo.CurrentCulture.Name; BulletinEditViewModel bulletin = _bulletinService.GetBulletinDetail(bullet_id, language_id, out string resultCode); ViewBag.SelectClassType = _bulletinService.GetAllClassType(language_id).ToSelectList(ct => ct.CLASS_TYPE, ct => ct.CLASS_NAME); if (bulletin == null) { string errorCode = _localizer[resultCode].Value; } return(View(bulletin)); }
public async Task <IActionResult> Edit(string id) { BulletinEditViewModel webModel = new BulletinEditViewModel { Title = "", Content = "", Target = 0, Type = 0 }; if (!string.IsNullOrEmpty(id)) { //编辑页面,加载公告相关信息 webModel = await _service.GetBulletinAsync(Convert.ToInt64(id), _context); } return(View(webModel)); }
/// <summary> /// 新增公告数据 /// </summary> /// <param name="webModel">公告编辑页视图模型</param> /// <param name="context">数据库上下文对象</param> /// <returns></returns> public async Task <bool> InsertBulletinAsync(BulletinEditViewModel webModel, ApplicationDbContext context) { try { //Add the Bulletion Data var model = await HomeRepository.InsertAsync(webModel.Title, (short)webModel.Target, (short)webModel.Type, webModel.Content, context); //Make the transaction union var index = await context.SaveChangesAsync(); return(index == 1 ? true : false); } catch (Exception ex) { _logger.LogError("创建新公告失败:{0},\r\n内部错误详细信息:{1}", ex.Message, ex.InnerException.Message); return(false); } }
/// <summary> /// 获取公告数据 /// </summary> /// <param name="id">公告编号</param> /// <param name="context">数据库上下文对象</param> /// <returns></returns> public async Task <BulletinEditViewModel> GetBulletinAsync(long id, ApplicationDbContext context) { var webModel = new BulletinEditViewModel(); try { var model = await HomeRepository.GetEntityAsync(id, context); webModel.Title = model.Title; webModel.Id = model.Id.ToString(); webModel.Content = model.Content; webModel.Target = (EnumType.BulletinTarget)model.Target; webModel.Type = (EnumType.BulletinType)model.Type; } catch (Exception ex) { _logger.LogError("获取公告数据失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message); } return(webModel); }
/// <summary> /// 更新公告数据 /// </summary> /// <param name="webModel">公告编辑页视图模型</param> /// <param name="context">数据库上下文对象</param> /// <returns></returns> public async Task <bool> UpdateBulletinAsync(BulletinEditViewModel webModel, ApplicationDbContext context) { try { //Update Bulletin Data HomeRepository.UpdateAsync(Convert.ToInt64(webModel.Id), webModel.Title, (short)webModel.Target, (short)webModel.Type, webModel.Content, context); //Add Operate Information var operate = string.Format("修改公告信息,公告编号:{0}", webModel.Id); PSURepository.InsertRecordAsync("Bulletin", "HomeDomain", "UpdateBulletinAsync", operate, (short)PSURepository.OperateCode.Update, Convert.ToInt64(webModel.Id), context); var index = await context.SaveChangesAsync(); return(index == 2 ? true : false); } catch (Exception ex) { _logger.LogError("更新公告数据失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message); return(false); } }