internal static bool CheckIfTouch(string accCode, NetAdminContext db)
        {
            AccessionCodes ac = db.AccessionCodes.Where(o => o.Code == accCode).FirstOrDefault();

            System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@@@@@@@" + accCode);
            System.Diagnostics.Debug.WriteLine(ac.IsTouch);
            if (ac != null)
            {
                if (ac.IsTouch.Trim() == "Y")
                {
                    return(true);
                }
                return(false);
            }
            return(false);
        }
        internal string Recover(string xmlpath)
        {
            try
            {
                db.ChangeTracker.AutoDetectChangesEnabled = false;
                db.Database.ExecuteSqlCommand("delete from AccLoc");
                db.Database.ExecuteSqlCommand("delete from AccessionCodes");
                db.Database.ExecuteSqlCommand("delete from Location");

                int    i        = 0;
                string fullpath = xmlpath;
                // System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@@@@@@@");
                if (!(File.Exists(fullpath)))
                {
                    return("No XML file found at given path. Please check the path");
                }
                else
                {
                    HashSet <String> codes    = new HashSet <string>();
                    XElement         xelement = XElement.Load(fullpath);
                    //  System.Diagnostics.Debug.WriteLine(fullpath);
                    IEnumerable <XElement> locations = xelement.Elements();
                    foreach (var location in locations)
                    {
                        Location l = new Location();
                        l.Name = location.Element("name").Value;
                        if (location.Element("status").Value != null && location.Element("status").Value.Trim() != "")
                        {
                            l.Status = location.Element("status").Value;
                        }

                        l.Code = location.Element("code").Value;
                        if (location.Element("path").Value != null && location.Element("path").Value.Trim() != "")
                        {
                            l.Path = location.Element("path").Value;
                        }
                        if (location.Element("server").Value != null && location.Element("server").Value.Trim() != "")
                        {
                            l.Server = location.Element("server").Value;
                        }
                        if (location.Element("retentionperiod") != null && location.Element("retentionperiod").Value.Trim() != "")
                        {
                            l.RetentionPeriod = Convert.ToInt32(location.Element("retentionperiod").Value);
                        }
                        if (location.Element("diagnosticlevel") != null && location.Element("diagnosticlevel").Value.Trim() != "")
                        {
                            l.DiagnosticLevel = Convert.ToInt32(location.Element("diagnosticlevel").Value);
                        }
                        if (location.Element("username") != null && location.Element("username").Value.Trim() != "")
                        {
                            l.Username = location.Element("username").Value;
                        }
                        if (location.Element("password") != null && location.Element("password").Value.Trim() != "")
                        {
                            l.Passwrd = location.Element("password").Value;
                        }
                        if (location.Element("host") != null && location.Element("host").Value.Trim() != "")
                        {
                            l.Host = location.Element("host").Value;
                        }
                        if (location.Element("port") != null && location.Element("port").Value.Trim() != "")
                        {
                            l.Port = location.Element("port").Value;
                        }
                        if (location.Element("directory") != null && location.Element("directory").Value.Trim() != "")
                        {
                            l.DirectoryPath = location.Element("directory").Value;
                        }
                        if (location.Element("isFTP") != null && location.Element("isFTP").Value.Trim() != "")
                        {
                            l.IsFTP = location.Element("isFTP").Value;
                        }
                        else
                        {
                            l.IsFTP = "N";
                        }

                        if (location.Element("configfileversion") != null && location.Element("configfileversion").Value.Trim() != "")
                        {
                            l.ConfigFileVersion = Convert.ToInt32(location.Element("configfileversion").Value);
                        }


                        l.CreatedAt = DateTime.Now;
                        l.UpdatedAt = DateTime.Now;
                        db.Location.Add(l);
                        db.SaveChanges();
                        if (location.Elements("accession") != null)
                        {
                            foreach (var ac in location.Elements("accession").GroupBy(e => e.Value).Select(x => x.First())) //to handle duplicate accessions within the same location
                            {
                                if (ac != null && ac.Value.Trim() != "")                                                    //using a in memory set as cache to check for duplicate instead of using db query every time and adding unique element to the set as well to the db
                                {
                                    if (!codes.Contains(ac.Value.Trim()))
                                    {
                                        codes.Add(ac.Value.Trim());
                                        AccessionCodes acode = new AccessionCodes();
                                        acode.Code      = ac.Value.Trim();
                                        acode.IsTouch   = ac.Attribute("isTouch") == null ? "N" : ac.Attribute("isTouch").Value.Trim();
                                        acode.CreatedAt = DateTime.Now;
                                        acode.UpdatedAt = DateTime.Now;
                                        db.AccessionCodes.Add(acode);
                                    }
                                    //AccessionCodes existing = db.AccessionCodes.Where(o => o.Code == ac.Value.Trim()).FirstOrDefault();
                                    //if (existing == null)
                                    //{
                                    //    AccessionCodes acode = new AccessionCodes();
                                    //    acode.Code = ac.Value.Trim();
                                    //    acode.IsTouch = ac.Attribute("isTouch")==null?"N": ac.Attribute("isTouch").Value.Trim();
                                    //    acode.CreatedAt = DateTime.Now;
                                    //    acode.UpdatedAt = DateTime.Now;
                                    //    db.AccessionCodes.Add(acode);

                                    //       // db.SaveChanges();
                                    //}

                                    AccLoc acl = new AccLoc();
                                    acl.LocCode   = location.Element("code").Value;
                                    acl.AccCode   = ac.Value;
                                    acl.CreatedAt = DateTime.Now;
                                    acl.UpdatedAt = DateTime.Now;
                                    db.AccLoc.Add(acl);

                                    //db.SaveChanges();
                                }
                                if (i % 50000 == 0)  //batches
                                {
                                    db.SaveChanges();
                                }
                                i++;
                            }
                            db.SaveChanges();
                        }
                    }



                    return("Database Restored Successfully. Please refresh the page.");
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }