public async Task <IActionResult> CreateLaborDetail(CreateLaborDetailViewModel model) { if (await _laborHeadService.CreateLaborDetailAsync(model)) { return(Ok()); } else { return(BadRequest("用户已选择过劳保")); } }
/// <summary> /// 创建一个人的劳保 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <bool> CreateLaborDetailAsync(CreateLaborDetailViewModel model) { LaborDetail existLaborDetail = await _laborDetailRepository.GetAll().FirstOrDefaultAsync(m => m.UserId == model.UserId && m.LaborId == model.LaborId); if (existLaborDetail != null) { existLaborDetail.Option = model.Option; existLaborDetail.Goods = model.Goods; await _laborDetailRepository.EditAsync(existLaborDetail); } else { await _laborDetailRepository.CreateAsync(new LaborDetail { UserId = model.UserId, LaborId = model.LaborId, Option = model.Option, Goods = model.Goods }); } return(true); }