Exemple #1
0
        public void Create(string id)
        {
            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    //create new row
                    var newRow = new RPT_COVID19EX();
                    newRow.PERSON_ID   = id;
                    newRow.REPORTER    = 1;
                    newRow.CREATED_DT  = DateTime.Now;
                    newRow.TRAVEL_FLAG = false;
                    newRow.REPORT_DT   = DateTime.Now;

                    context.RPT_COVID19EX.Add(newRow);
                    context.SaveChanges();

                    dbContextTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw ex;
                }
            }
        }
        public string Create(CovidHealthCheckViewModel ViewModel)
        {
            using (var dbContextTransaction = context.Database.BeginTransaction())
            {
                try
                {
                    //create new row
                    var newRow = new COVID_HEALTHCHECK();
                    newRow.TRAVEL_IN_14_DAYS_FLAG          = ViewModel.TRAVEL_IN_14_DAYS_FLAG;
                    newRow.TRAVEL_IN_14_DAYS_COUNTRY       = ViewModel.TRAVEL_IN_14_DAYS_COUNTRY;
                    newRow.CLOSE_TO_FOREIGNER_FLAG         = ViewModel.CLOSE_TO_FOREIGNER_FLAG;
                    newRow.OCCUPATION_ID                   = ViewModel.OCCUPATION_ID;
                    newRow.CLOSE_TO_PATIENT_FLAG           = ViewModel.CLOSE_TO_PATIENT_FLAG;
                    newRow.TRAVEL_IN_14_DAYS_OTHER_FLAG    = ViewModel.TRAVEL_IN_14_DAYS_OTHER_FLAG;
                    newRow.TRAVEL_IN_14_DAYS_COUNTRY_OTHER = ViewModel.TRAVEL_IN_14_DAYS_COUNTRY_OTHER;
                    newRow.MEDICAL_STAFF_FLAG              = ViewModel.MEDICAL_STAFF_FLAG;
                    newRow.AGE                 = ViewModel.AGE;
                    newRow.AMPHUR_ID           = ViewModel.AMPHUR_ID;
                    newRow.FRIENT_HAS_FLU_FLAG = ViewModel.FRIENT_HAS_FLU_FLAG;
                    newRow.LOCATION_TYPE_ID    = ViewModel.LOCATION_TYPE_ID;
                    newRow.CREATED_DT          = DateTime.Now;
                    context.COVID_HEALTHCHECK.Add(newRow);
                    context.SaveChanges();

                    if (ViewModel.SYMTOMS != null && ViewModel.SYMTOMS.Count() > 0)
                    {
                        foreach (var st in ViewModel.SYMTOMS)
                        {
                            var c = new COVID_HEALTHCHECK_SYMTOMS();
                            c.REPORTER_ID = newRow.ID;
                            c.SYMTOMS_ID  = st;
                            context.COVID_HEALTHCHECK_SYMTOMS.Add(c);
                            context.SaveChanges();
                        }
                    }

                    dbContextTransaction.Commit();

                    //summaryResult
                    // 1. check symtoms
                    if (ViewModel.SYMTOMS != null && ViewModel.SYMTOMS.Count() > 0)
                    {
                        if (ViewModel.SYMTOMS.Count() > 1 && ViewModel.SYMTOMS.Contains(1))
                        {
                            return("3");
                        }
                        else
                        {
                            return("2");
                        }
                    }

                    // 2. check country
                    if (ViewModel.TRAVEL_IN_14_DAYS_COUNTRY.HasValue)
                    {
                        var watchout = context.LUT_COUNTRY.Find(ViewModel.TRAVEL_IN_14_DAYS_COUNTRY.Value);
                        return(watchout.WATCH_OUT_FLAG.Value == true ? "3" : "1");
                    }

                    // 3. check support info
                    if (ViewModel.TRAVEL_IN_14_DAYS_FLAG == false && ViewModel.CLOSE_TO_FOREIGNER_FLAG == false &&
                        ViewModel.CLOSE_TO_PATIENT_FLAG == false && ViewModel.TRAVEL_IN_14_DAYS_OTHER_FLAG == false &&
                        ViewModel.MEDICAL_STAFF_FLAG == false)
                    {
                        return("1");
                    }
                    else
                    {
                        return("2");
                    }
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw ex;
                }
            }
        }
        public bool Save()
        {
            var saved = _context.SaveChanges();

            return(saved >= 0 ? true : false);
        }