Esempio n. 1
0
        private string CreateTable(string formdata, string formname)
        {
            SQLDataManager sql = new SQLDataManager(false);


            //string query_create = "CREATE TABLE template_" + formname.Replace(" ", "").ToLower() + " (Id INT IDENTITY(1,1), accountid int, locationid int, patientid varchar(100)";
            string query_create = "CREATE TABLE template_" + formname.Replace(" ", "").ToLower() + " (Id INT, encodedby int foreign key references ApplicationUser(AppUserId), encounterid int foreign key references checkin(encounterid),accountid int, locationid int, patientid varchar(100)";

            // s789990-
            //List<Component> request = new List<Component>();
            try
            {
                FormDirect myform = new FormDirect();
                myform = JsonConvert.DeserializeObject <FormDirect>(formdata);
                for (int k = 0; k < myform.components.Count; k++)
                {
                    //Detail mydetail = mycomponent.components[i].;
                    query_create += "," + myform.components[k].key.ToString().Replace(" ", "").ToLower() + " varchar(100)";
                }
                //Form myform = new Form();
                //myform = JsonConvert.DeserializeObject<Form>(formdata);

                //for (int i = 0; i < myform.components.Count; i++)
                //{
                //    Columns mycolumn = myform.components[i];
                //    for (int j = 0; j < mycolumn.columns.Count; j++)
                //    {
                //        Component mycomponent = mycolumn.columns[j];
                //        for (int k = 0; k < mycomponent.components.Count; k++)
                //        {
                //            //Detail mydetail = mycomponent.components[i].;
                //            query_create += "," + mycomponent.components[k].key.ToString().Replace(" ", "").ToLower() + " varchar(100)";
                //        }
                //    }
                //    //query_create += ","+myform.components[i].key.ToString().Replace(" ", "").ToLower() + " varchar(100)";

                //}
            }
            catch (Exception)
            {
                FormDirect myform = new FormDirect();
                myform = JsonConvert.DeserializeObject <FormDirect>(formdata);
                for (int k = 0; k < myform.components.Count; k++)
                {
                    //Detail mydetail = mycomponent.components[i].;
                    query_create += "," + myform.components[k].key.ToString().Replace(" ", "").ToLower() + " varchar(100)";
                }
            }

            //query_create += $" , Dateadded datetime DEFAULT GETDATE(), CONSTRAINT [{formname.Replace(" ", "").ToLower()+"_"+Guid.NewGuid().ToString()}] PRIMARY KEY CLUSTERED ([id] asc) )";
            query_create += $" , Dateadded varchar(100) default '', oldid int default 0,CONSTRAINT [{formname.Replace(" ", "").ToLower() + "_" + Guid.NewGuid().ToString()}] PRIMARY KEY CLUSTERED ([id] asc)   )";
            sql.ExecuteNonQuery(query_create, CommandType.Text);

            return("Success");
        }
Esempio n. 2
0
        public IActionResult SaveData(FormData request)
        {
            SQLDataManager sql = new SQLDataManager(false);

            if (request != null && request.formname != null && request.formdata != null)
            {
                string query = "insert into template_" + request.formname.Replace(" ", "").ToLower() + " " + request.formdata;
                sql.ExecuteNonQuery(query, CommandType.Text);
                return(Ok("Success"));
            }
            else
            {
                return(BadRequest("Invalid/Bad Request"));
            }
        }