public IActionResult GetClaimFormDetail([FromQuery] int formid) { _logger.LogInformation("Query ClaimFormDetail with formid:{formid}", formid); var tmp = _context.ClaimFormChemicalMap .Where(u => u.ClaimFormId == formid) .Include(u => u.Chemical) .Include(u => u.ClaimForm) .ToList(); var ret = new PostClaimFormParam { Form = tmp[0].ClaimForm, Chemicals = tmp.Select(t => t.Chemical).ToList() }; return(Ok(ret)); }
public IActionResult Claim([FromBody] PostClaimFormParam param) { _logger.LogInformation("Post claim form. formid: {formid}", param.Form.Id); _logger.LogInformation("With {count} chemicals.", param.Chemicals.Count); try { param.Form.SubmitTime = DateTime.Now; HttpWrapper.CallServiceByPost("/api/claim/apply", JsonSerializer.Serialize(param)); return(Ok()); } catch (Exception e) { _logger.LogError(e.Message); return(NotFound(e.Message)); } }
public IActionResult PostClaimForm([FromBody] PostClaimFormParam param) { _logger.LogInformation("Get posted claim form. formid: {formid}", param.Form.Id); var form = param.Form; form.State = Utils.FormState.InProcess; _context.ClaimForms.Add(form); _context.SaveChanges(); // data format foreach (var chemical in param.Chemicals) { var entity = new ClaimFormChemical { ChemicalId = chemical.ChemicalId, ClaimForm = form, ClaimFormId = form.Id }; _context.ClaimFormChemicalMap.Add(entity); var dbChemical = _context.Chemicals.Where(c => c.ChemicalId == chemical.ChemicalId).Single(); dbChemical.State = ChemicalState.InApplication; } var roles = _context.Roles .Where(r => r.RoleName == "LabTeacher" && r.LabId.HasValue? r.LabId == form.LabId:false) .ToList(); _logger.LogInformation("Send message to {0} roles.", roles.Count); _logger.LogInformation("Role list: "); foreach (var role in roles) { _logger.LogInformation("Role id: {0}, name: {1}", role.RoleId, role.RoleName); // send message to role var msg = new NotificationMessage { FormId = form.Id, FormType = FormType.ClaimForm, IsSolved = false, RoleId = role.RoleId }; _context.NotificationMessages.Add(msg); } _context.SaveChanges(); return(Ok()); }