public async Task <IActionResult> AddForm([FromBody] AddFormInfo info) { var form = new TCL_PNC { TCL_PNCId = Guid.NewGuid().ToString().ToLower(), Barangay = info.Barangay, Municipality = info.Municipality, Province = info.Province, Region = info.Region, UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value, }; await _appDbContext.AddAsync(form); await _appDbContext.SaveChangesAsync(); return(Ok(form.TCL_PNCId)); }
public async Task <IActionResult> Upload([FromBody] TCL_PNC info) { try { var frm = await _appDbContext.TCL_PNCs.FirstOrDefaultAsync(p => p.TCL_PNCId == info.TCL_PNCId); if (frm == null) { if (info.LastUploaded == null) { info.LastUploaded = DateTime.UtcNow; } _appDbContext.Add(info); } else { frm.Barangay = info.Barangay; frm.Municipality = info.Municipality; frm.Province = info.Province; frm.Region = info.Region; frm.LastUploaded = DateTime.UtcNow; } foreach (var entry in info.Entries) { var foo = await _appDbContext.TCL_PNC_Entries.FirstOrDefaultAsync(p => p.TCL_PNC_EntryId == entry.TCL_PNC_EntryId); if (foo == null) { _appDbContext.Add(entry); } else { foo.DateOfRegistration = entry.DateOfRegistration; foo.FamilySerialNumber = entry.FamilySerialNumber; foo.Name = entry.Name; foo.Address = entry.Address; foo.Age = entry.Age; foo.LMPDate = entry.LMPDate; foo.LMPGP = entry.LMPGP; foo.EDC = entry.EDC; foo.PrenatalVisitTrimester1 = entry.PrenatalVisitTrimester1; foo.PrenatalVisitTrimester2 = entry.PrenatalVisitTrimester2; foo.PrenatalVisitTrimester3 = entry.PrenatalVisitTrimester3; foo.TetanusStatus = entry.TetanusStatus; foo.DateTetanusToxiodVaccine1 = entry.DateTetanusToxiodVaccine1; foo.DateTetanusToxiodVaccine2 = entry.DateTetanusToxiodVaccine2; foo.DateTetanusToxiodVaccine3 = entry.DateTetanusToxiodVaccine3; foo.DateTetanusToxiodVaccine4 = entry.DateTetanusToxiodVaccine4; foo.DateTetanusToxiodVaccine5 = entry.DateTetanusToxiodVaccine5; foo.IronWithFolicDateGiven1 = entry.IronWithFolicDateGiven1; foo.IronWithFolicNumberGiven1 = entry.IronWithFolicNumberGiven1; foo.IronWithFolicDateGiven2 = entry.IronWithFolicDateGiven2; foo.IronWithFolicNumberGiven2 = entry.IronWithFolicNumberGiven2; foo.IronWithFolicDateGiven3 = entry.IronWithFolicDateGiven3; foo.IronWithFolicNumberGiven3 = entry.IronWithFolicNumberGiven3; foo.IronWithFolicDateGiven4 = entry.IronWithFolicDateGiven4; foo.IronWithFolicNumberGiven4 = entry.IronWithFolicNumberGiven4; foo.IronWithFolicDateGiven5 = entry.IronWithFolicDateGiven5; foo.IronWithFolicNumberGiven5 = entry.IronWithFolicNumberGiven5; foo.IronWithFolicDateGiven6 = entry.IronWithFolicDateGiven6; foo.IronWithFolicNumberGiven6 = entry.IronWithFolicNumberGiven6; foo.DateSTITested = entry.DateSTITested; foo.DateSTIResult = entry.DateSTIResult; foo.DateSTIPenicillin = entry.DateSTIPenicillin; foo.PregnancyDateTerminated = entry.PregnancyDateTerminated; foo.PregnancyOutcome = entry.PregnancyOutcome; foo.PregnancyGender = entry.PregnancyGender; foo.BirthWeight = entry.BirthWeight; foo.PlaceOfHealthFacility = entry.PlaceOfHealthFacility; foo.PlaceOfNIO = entry.PlaceOfNIO; foo.AttendedBy = entry.AttendedBy; foo.Remarks = entry.Remarks; foo.Remarks = entry.Remarks; } } await _appDbContext.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }