Exemple #1
0
        public async Task <IActionResult> OnPostAsync(int id = 0)
        {
            ErrorMessage = "";
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ErrorMessage = "";
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = await _roomAppService.Delete(id);

            if (!result.IsSuccess)
            {
                ErrorMessage = result.Message;
                return(Page());
            }
            else
            {
                return(RedirectToPage("/Map/Index"));
            }

            /*
             * try
             * {
             *  var room = await _db.Rooms.FindAsync(id);
             *  if (room == null)
             *  {
             *      ErrorMessage = $"房间 {id} 不存在!";
             *      return Page();
             *  }
             *  _db.Rooms.Remove(room);
             *  await _db.SaveChangesAsync();
             *
             *  await AddSuccess(new OperatorLog
             *  {
             *      Type = OperatorLogType.删除房间,
             *      Content = JsonConvert.SerializeObject(room)
             *  });
             * }
             * catch (Exception ex)
             * {
             *  ErrorMessage = ex.Message;
             *  await AddError(new OperatorLog
             *  {
             *      Type = OperatorLogType.删除房间,
             *      Content = $"id={id},ErrorMessage={ErrorMessage}"
             *  });
             *  return Page();
             * }
             *
             * return Redirect(UrlReferer);
             */
        }
 public ActionResult DeleteConfirmed(Guid id)
 {
     _roomAppService.Delete(id);
     return(RedirectToAction("Index"));
 }