//VS中Add方法中知道 保质期和生产日期来计算有效期至的方法和代码
if (r.Success)
{
r.Data = entities.ToExtJsAddResultData<CaiGouDanShangPin, Guid>(); // 返回增加的实体的ID和Timestamp集合
r.Messages.Add($"新增{entities.Count}条记录成功!");
var baozhiQi = entities.FirstOrDefault();
if (baozhiQi != null)
{
if (baozhiQi.BaoZhiQiDanWei == "年")
{
var t = Convert.ToInt32(baozhiQi.BaoZhiQi);
DateTime dt = DateTime.Parse(baozhiQi.ShengChanRiQi.ToString("yyyy-MM-dd"));
baozhiQi.YouXiaoQiZhi = dt.AddYears(t);
baozhiQi.Update().OnlySaveFields(e => e.YouXiaoQiZhi).SaveToDBAsync().Wait();
}
if (baozhiQi.BaoZhiQiDanWei == "月")
{
var t = Convert.ToInt32(baozhiQi.BaoZhiQi);
DateTime dt = DateTime.Parse(baozhiQi.ShengChanRiQi.ToString("yyyy-MM-dd"));
baozhiQi.YouXiaoQiZhi = dt.AddMonths(t);
baozhiQi.Update().OnlySaveFields(e => e.YouXiaoQiZhi).SaveToDBAsync().Wait();
}
if (baozhiQi.BaoZhiQiDanWei == "日")
{
var t = Convert.ToInt32(baozhiQi.BaoZhiQi);
DateTime dt = DateTime.Parse(baozhiQi.ShengChanRiQi.ToString("yyyy-MM-dd"));
baozhiQi.YouXiaoQiZhi = dt.AddDays(t);
baozhiQi.Update().OnlySaveFields(e => e.YouXiaoQiZhi).SaveToDBAsync().Wait();
}
}
}