public string EditLogTest(EditLogModel model) { if (!ModelState.IsValid) { return("failded"); } var queryOfLog = _context.Logs.Where(l => l.Id == model.Id); if (!queryOfLog.Any()) { return("failed"); } var log = queryOfLog.First(); log.Content = model.Content; log.Title = model.Title; //_context.Logs.Remove(log); _context.SaveChanges(); return("finished"); }
public ActionResult Edit(Guid componentId) { var repository = CurrentAccountDbContext.GetLogConfigRepository(); var config = repository.GetByComponentId(componentId); var model = new EditLogModel { Id = componentId, IsFatalEnabled = config.IsFatalEnabled, IsErrorEnabled = config.IsErrorEnabled, IsWarningEnabled = config.IsWarningEnabled, IsInfoEnabled = config.IsInfoEnabled, IsDebugEnabled = config.IsDebugEnabled, IsTraceEnabled = config.IsTraceEnabled, ComponentName = config.Component.DisplayName }; return(PartialView(model)); }
public ActionResult Edit(EditLogModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } var repository = CurrentAccountDbContext.GetLogConfigRepository(); var config = repository.GetByComponentId(model.Id); model.ComponentName = config.Component.DisplayName; config.IsFatalEnabled = model.IsFatalEnabled; config.IsErrorEnabled = model.IsErrorEnabled; config.IsWarningEnabled = model.IsWarningEnabled; config.IsInfoEnabled = model.IsInfoEnabled; config.IsDebugEnabled = model.IsDebugEnabled; config.IsTraceEnabled = model.IsTraceEnabled; config.LastUpdateDate = Now(); CurrentAccountDbContext.SaveChanges(); return(GetSuccessJsonResponse()); }
public async Task <IActionResult> EditLog(EditLogModel model, string returnUrl) { if (ModelState.IsValid) { ViewData["ReturnUrl"] = returnUrl; //如果这个Log存在,并且属于当前用户 var user = await _userManager.GetUserAsync(User); var query = _context.Logs.Where(q => q.Id == model.Id && q.BelongerId == user.Id); if (query.Any()) { var log = query.First(); log.Title = model.Title; log.Content = model.Content; _context.SaveChanges(); return(Redirect(returnUrl)); } return(View(model)); //没有添加出错信息 } return(View(model)); //没有添加出错信息 }
public async Task <IActionResult> EditLog(string logId, string returnUrl = null) { if (ModelState.IsValid) { ViewData["ReturnUrl"] = returnUrl; //如果这个Log存在,并且属于当前用户 var user = await _userManager.GetUserAsync(User); var query = _context.Logs.Where(q => q.Id == logId && q.BelongerId == user.Id); if (query.Any()) { var log = query.First(); var model = new EditLogModel() { Id = log.Id, Content = log.Content, Title = log.Title }; return(View(model)); } throw new Exception("error"); } throw new Exception("error"); }