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

            var result = await _emailAppService.Update(id, Email);

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

            /*
             * try
             * {
             *  var email = await _db.Emails.FindAsync(id);
             *  if (email == null)
             *  {
             *      ErrorMessage = $"邮件 {id} 不存在!";
             *      return Page();
             *  }
             *  var content = DifferenceComparison(email, Email);
             *  _mapper.Map(Email, email);
             *
             *  await _db.SaveChangesAsync();
             *
             *
             *
             *  await AddSuccess(new OperatorLog
             *  {
             *      Type = OperatorLogType.修改邮件,
             *      Content = $"Id = {id},Data = {content}"
             *  });
             * }
             * catch (Exception ex)
             * {
             *  ErrorMessage = ex.Message;
             *  await AddError(new OperatorLog
             *  {
             *      Type = OperatorLogType.修改邮件,
             *      Content = $"Id = {id},Data={JsonConvert.SerializeObject(Email)},ErrorMessage={ErrorMessage}"
             *  });
             *  return Page();
             * }
             *
             * return Redirect(UrlReferer);
             */
        }
Пример #2
0
        // PUT api/<controller>/5
        public async Task <HttpResponseMessage> Put([FromBody] Email email)
        {
            try
            {
                await _emailAppService.Update(email);

                NotificationHub.SendMessageUpdate(
                    string.Format("Alterado com Sucesso {0}", Guid.NewGuid()));

                return(await Task.Factory.StartNew(() => new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                }));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }