public HttpResponseMessage SaveNewDocumentName(SaveNewDocument data)
        {
            var context = new SMARTINDEXEntities();
            List <Cst_DocName> newCst_DocName = new List <Cst_DocName>();
            var NewDocName = new Cst_DocName
            {
                DocName   = data.DocName,
                Createdby = data.Createdby
            };

            newCst_DocName.Add(NewDocName);
            context.Cst_DocName.AddRange(newCst_DocName);
            context.SaveChanges();
            return(Request.CreateResponse(HttpStatusCode.OK, "Saved successfully"));
        }
        public HttpResponseMessage SaveClassifyData(List <SaveClassifyConfig> data)
        {
            var    context               = new SMARTINDEXEntities();
            string addedind              = "added";
            string modifiedind           = "Modified";
            string docNamechangeitem     = "docName";
            string docTypeNamechangeitem = "docTypeName";
            string Keywordchangeitem     = "keyword";
            //New doc Name
            var NewdocName = data.FindAll(e => (e.Ind == addedind && e.Changeitem == docNamechangeitem)).ToList();

            if (NewdocName.Count > 0)
            {
                List <Cst_DocName> new_DocName = new List <Cst_DocName>();
                foreach (var d in NewdocName)
                {
                    var cst_docName = new Cst_DocName
                    {
                        DocName  = d.docName,
                        isactive = true
                    };
                    new_DocName.Add(cst_docName);
                }
                context.Cst_DocName.AddRange(new_DocName);
                context.SaveChanges();
            }

            //New docType

            var NewdocTypeName = (from d in data where (d.Ind == addedind && d.Changeitem == docTypeNamechangeitem)select new { d.docName, d.docTypeName, d.havingPageNumbers, d.Ind, d.minPages, d.maxPages, d.pageNumberFormat, d.priority, d.addIfPrevTypeisSame, d.fileName }).ToList();

            if (NewdocTypeName.Count > 0)
            {
                var NewdocTypeNameList = (from para in NewdocTypeName
                                          join d1 in DBContext.Cst_DocName
                                          on para.docName equals d1.DocName
                                          select new { d1.Cst_DocNameID, para.docTypeName, para.havingPageNumbers, para.Ind, para.minPages, para.maxPages, para.pageNumberFormat, para.priority, para.addIfPrevTypeisSame, para.fileName }).ToList();

                List <Cst_DocTypes> new_DocTypeName = new List <Cst_DocTypes>();
                foreach (var d in NewdocTypeNameList)
                {
                    var cst_DocTypes = new Cst_DocTypes
                    {
                        DocTypeName         = d.docTypeName,
                        Cst_DocNameID       = d.Cst_DocNameID,
                        MinPages            = d.minPages,
                        MaxPages            = d.maxPages,
                        HavingPageNumbers   = d.havingPageNumbers,
                        PageNumberFormat    = d.pageNumberFormat,
                        AddIfPrevTypeisSame = d.addIfPrevTypeisSame,
                        Priority            = d.priority,
                        FileName            = d.fileName
                    };
                    new_DocTypeName.Add(cst_DocTypes);
                }
                context.Cst_DocTypes.AddRange(new_DocTypeName);
                context.SaveChanges();
            }

            //New Keyword

            var NewKeyword = (from d in data where (d.Ind == addedind && d.Changeitem == Keywordchangeitem)select new { d.docName, d.docTypeName, d.keyword, d.percentageofsimilarity, d.keywordThresholdpercetage, d.zoneArea, d.casesensitive, d.pagePosition }).ToList();

            if (NewKeyword.Count > 0)
            {
                var NewKeywordList = (from para in NewKeyword
                                      join d1 in DBContext.Cst_DocName
                                      on para.docName equals d1.DocName
                                      join d2 in DBContext.Cst_DocTypes
                                      on(d1.Cst_DocNameID.ToString() + '_' + para.docTypeName) equals(d2.Cst_DocNameID.ToString() + '_' + d2.DocTypeName)
                                      select new { d1.Cst_DocNameID, d2.Cst_DocTypeID, para.docTypeName, para.keyword, para.percentageofsimilarity, para.keywordThresholdpercetage, para.zoneArea, para.casesensitive, para.pagePosition }).ToList();

                List <Cst_Keywords> new_Keywords = new List <Cst_Keywords>();
                foreach (var d in NewKeywordList)
                {
                    var cst_Keywords = new Cst_Keywords
                    {
                        Keyword            = d.keyword,
                        Cst_DocTypeID      = d.Cst_DocTypeID,
                        Thresholdpercetage = Convert.ToDecimal(d.keywordThresholdpercetage),
                        ZoneArea           = d.zoneArea,
                        Casesensitive      = d.casesensitive == "1"?true:false,
                        PagePosition       = d.pagePosition,
                        IsActive           = 1
                                             //percentageofsimilarity = d.percentageofsimilarity
                    };
                    new_Keywords.Add(cst_Keywords);
                }
                context.Cst_Keywords.AddRange(new_Keywords);
                context.SaveChanges();
            }

            //Modified docType

            var ModdocTypeName = (from d in data where (d.Ind == modifiedind && d.Changeitem == docTypeNamechangeitem)select new { d.Changeitem, d.Ind, d.changeproperty, d.docName, d.docTypeName, d.newvalue, d.oldValue }).ToList();

            if (ModdocTypeName.Count > 0)
            {
                var ModdocTypeNameList = (from para in ModdocTypeName
                                          join d1 in DBContext.Cst_DocName
                                          on para.docName equals d1.DocName
                                          select new { d1.Cst_DocNameID, para.Changeitem, para.Ind, para.changeproperty, para.docName, para.docTypeName, para.newvalue, para.oldValue }).ToList();

                var ModdocTypeNameList1 = (from para in ModdocTypeNameList
                                           join d1 in DBContext.Cst_DocTypes
                                           on para.docTypeName + "_" + para.Cst_DocNameID.ToString() equals d1.DocTypeName + "_" + d1.Cst_DocNameID.ToString()
                                           select new { d1.Cst_DocNameID, d1.Cst_DocTypeID, para.Changeitem, para.Ind, para.changeproperty, para.docName, para.docTypeName, para.newvalue, para.oldValue }).ToList();
                Cst_DocTypes stud;
                foreach (var val in ModdocTypeNameList1)
                {
                    stud = DBContext.Cst_DocTypes.Where(s => s.Cst_DocTypeID == val.Cst_DocTypeID).FirstOrDefault <Cst_DocTypes>();
                    if (val.changeproperty == "docTypeName")
                    {
                        stud.DocTypeName = val.newvalue;
                    }
                    if (val.changeproperty == "fileName")
                    {
                        stud.FileName = val.newvalue;
                    }
                    if (val.changeproperty == "maxPages")
                    {
                        stud.MaxPages = Convert.ToInt32(val.newvalue);
                    }
                    if (val.changeproperty == "minPages")
                    {
                        stud.MinPages = Convert.ToInt32(val.newvalue);
                    }
                    if (val.changeproperty == "havingPageNumbers")
                    {
                        stud.HavingPageNumbers = val.newvalue;
                    }
                    if (val.changeproperty == "addIfPrevTypeisSame")
                    {
                        stud.AddIfPrevTypeisSame = val.newvalue;
                    }
                    if (val.changeproperty == "pageNumberFormat")
                    {
                        stud.PageNumberFormat = val.newvalue;
                    }
                    if (val.changeproperty == "priority")
                    {
                        stud.Priority = Convert.ToInt32(val.newvalue);
                    }
                    DBContext.SaveChanges();
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK, "Saved successfully"));
        }