コード例 #1
0
        public async Task <IActionResult> AddForm([FromBody] AddFormInfo info)
        {
            var form = new TCL_FP
            {
                TCL_FPId     = 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_FPId));
        }
コード例 #2
0
        public async Task <IActionResult> Upload([FromBody] TCL_FP info)
        {
            try
            {
                var frm = await _appDbContext.TCL_FPs.FirstOrDefaultAsync(p => p.TCL_FPId == info.TCL_FPId);

                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_FP_Entries.FirstOrDefaultAsync(p => p.TCL_FP_EntryId == entry.TCL_FP_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.BirthDate = entry.BirthDate;

                        foo.TypeOfClient = entry.TypeOfClient;

                        foo.PresentMethod  = entry.PresentMethod;
                        foo.PreviousMethod = entry.PreviousMethod;

                        foo.DateNextService1         = entry.DateNextService1;
                        foo.DateAccomplishedService1 = entry.DateAccomplishedService1;

                        foo.DateNextService2         = entry.DateNextService2;
                        foo.DateAccomplishedService2 = entry.DateAccomplishedService2;

                        foo.DateNextService3         = entry.DateNextService3;
                        foo.DateAccomplishedService3 = entry.DateAccomplishedService3;

                        foo.DateNextService4         = entry.DateNextService4;
                        foo.DateAccomplishedService4 = entry.DateAccomplishedService4;

                        foo.DateNextService5         = entry.DateNextService5;
                        foo.DateAccomplishedService5 = entry.DateAccomplishedService5;

                        foo.DateNextService6         = entry.DateNextService6;
                        foo.DateAccomplishedService6 = entry.DateAccomplishedService6;

                        foo.DateNextService7         = entry.DateNextService7;
                        foo.DateAccomplishedService7 = entry.DateAccomplishedService7;

                        foo.DateNextService8         = entry.DateNextService8;
                        foo.DateAccomplishedService8 = entry.DateAccomplishedService8;

                        foo.DateNextService9         = entry.DateNextService9;
                        foo.DateAccomplishedService9 = entry.DateAccomplishedService9;

                        foo.DateNextService10         = entry.DateNextService10;
                        foo.DateAccomplishedService10 = entry.DateAccomplishedService10;

                        foo.DateNextService11         = entry.DateNextService11;
                        foo.DateAccomplishedService11 = entry.DateAccomplishedService11;

                        foo.DateNextService12         = entry.DateNextService12;
                        foo.DateAccomplishedService12 = entry.DateAccomplishedService12;

                        foo.DropoutDate   = entry.DropoutDate;
                        foo.DropoutReason = entry.DropoutReason;

                        foo.Remarks = entry.Remarks;
                    }
                }


                await _appDbContext.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }