我有一个实体框架核心项目
HttpPut
方法。
我有一个if/else语句,它检查两个布尔值,
isValid
和
isDeleted
.
在测试中,当我用向控制器发送对象时
isValid
设置为true和
is已删除
设置为false,则发送正确的电子邮件。
但如果我发送一个带有
isValid
设置为true和
is已删除
设置为true时,它不会发送电子邮件。
我的代码逻辑失控了吗?
谢谢
[HttpPut("{id}")]
public async Task<IActionResult> PutShoppingCart(long id, [FromBody] ShoppingCart shoppingCart)
{
_context.Entry(shoppingCart).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!ShoppingCartExists(id))
{
return NotFound();
}
else
{
throw;
}
}
if (shoppingCart.IsValid && !shoppingCart.IsDeleted)
{
try
{
_customerEmailerProcess.SendCustomerEmail(shoppingCart,10);
}
catch (Exception ex)
{
await HttpResponseWritingExtensions.WriteAsync(this.Response, "<script>alert('" + HttpUtility.HtmlEncode(ex) + "')</script>");
}
} else
{
if (shoppingCart.IsDeleted)
{
try
{
_customerEmailerProcess.SendCustomerEmail(shoppingCart, 20);
}
catch (Exception ex)
{
await HttpResponseWritingExtensions.WriteAsync(this.Response, "<script>alert('" + HttpUtility.HtmlEncode(ex) + "')</script>");
}
}
}
return NoContent();
}