Пример #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            ErrorMessage = "";
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = await _wareAppService.Add(Ware);

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

            /*
             * try
             * {
             *  var ware = _mapper.Map<WareEntity>(Ware);
             *
             *  if (ware.Effect == null)
             *  {
             *      ware.Effect = "";
             *  }
             *  await _db.Wares.AddAsync(ware);
             *
             *  await _db.SaveChangesAsync();
             *
             *  await AddSuccess(new OperatorLog
             *  {
             *      Type = OperatorLogType.复制物品,
             *      Content = JsonConvert.SerializeObject(Ware)
             *  });
             * }
             * catch (Exception ex)
             * {
             *  ErrorMessage = ex.Message;
             *  await AddError(new OperatorLog
             *  {
             *      Type = OperatorLogType.复制物品,
             *      Content = $"Data={JsonConvert.SerializeObject(Ware)},ErrorMessage={ErrorMessage}"
             *  });
             *  return Page();
             * }
             *
             *
             * return Redirect(UrlReferer);
             */
        }
Пример #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            ErrorMessage = "";
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = await _wareAppService.Add(Ware);

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

            /*
             * try
             * {
             *  await _wareAppService.Add(Ware);
             *
             *  await AddSuccess(new OperatorLog
             *  {
             *      Type = OperatorLogType.添加物品,
             *      Content = JsonConvert.SerializeObject(Ware)
             *  });
             * }
             * catch(Exception ex)
             * {
             *  ErrorMessage = ex.Message;
             *  await AddError(new OperatorLog
             *  {
             *      Type = OperatorLogType.添加物品,
             *      Content = $"Data={JsonConvert.SerializeObject(Ware)},ErrorMessage={ErrorMessage}"
             *  });
             *  return Page();
             * }
             *
             *
             *
             * return RedirectToPage("/Ware/Index");
             */
        }