public bool Import(string importPath, int userId)
        {
            bool ok = false;

            DataSheetFeedImport imp = new DataSheetFeedImport()
            {
                DateStamp   = DateTime.Now,
                UserId      = userId,
                FileName    = importPath,
                FileContent = ReadFile(importPath)
            };

            try
            {
                imp = sSvc.Validate(imp);

                if (imp.IsValid)
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.LoadXml(imp.FileContent);

                    XmlNode docRoot = xdoc.DocumentElement;

                    XmlNodeList datasheetDocs = docRoot.SelectNodes("Datasheet");

                    foreach (XmlNode datasheetDoc in datasheetDocs)
                    {
                        XmlDocument dsDoc = new XmlDocument();

                        Entity entity = new Entity()
                        {
                            Active     = true,
                            DateStamp  = DateTime.Now,
                            EntityType = (int)EntityTypeEnum.Product,
                            UserId     = userId
                        };

                        dsDoc.LoadXml(datasheetDoc.OuterXml);

                        entity.OtherId    = GetEntityID(dsDoc);
                        entity.EntityName = GetEntityName(dsDoc);

                        db.Entities.Add(entity);
                        db.SaveChanges();

                        // SaveChapter(entity, dsDoc, "InformationFromExportingSystem", userId);
                    }

                    db.Imports.Add(imp);
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Import File Name:" + importPath);
            }

            return(ok);
        }
Beispiel #2
0
        public Document Save(Document document)
        {
            if (document.Id == 0)
            {
                db.Add <Document>(document);
            }
            else
            {
                db.Update <Document>(document);
            }

            db.SaveChanges();

            return(document);
        }
        public bool Delete(User user)
        {
            bool ok = false;

            try
            {
                db.Users.Remove(user);
                db.SaveChanges();
                ok = true;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "UserService>Delete");
            }

            return(ok);
        }
Beispiel #4
0
        /// <summary>
        /// Updates an application setting
        /// </summary>
        ///<param name="appSetting"></param>
        /// <returns></returns>
        public bool Save(ApplicationSetting appSetting)
        {
            bool ok = false;

            try
            {
                if (appSetting.Id == 0)
                {
                    db.AppSettings.Add(appSetting);
                }
                else
                {
                    db.AppSettings.Update(appSetting);
                }
                ok = (db.SaveChanges() == 1);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "ApplicationSettingService>AddNew");
            }

            return(ok);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Entity Save(Entity entity)
        {
            if (entity.Id == 0)
            {
                db.Add <Entity>(entity);
            }
            else
            {
                db.Update(entity);
            }
            db.SaveChanges();

            return(entity);
        }
Beispiel #6
0
        public void LoadComponents()
        {
            try
            {
                List <Entity> entList = eSvc.GetByType(EntityTypeEnum.Component);
                db.Entities.RemoveRange(entList);
                db.SaveChanges();

                List <ApplicationSetting> appSetList = aSvc.GetByArea("SUBSTANCES");
                db.AppSettings.RemoveRange(appSetList);
                db.SaveChanges();

                XmlDocument xdoc = new XmlDocument();
                xdoc.Load("files/reg-substances-export.xml");

                XmlNode root = xdoc.DocumentElement;

                db.AppSettings.Add(new ApplicationSetting()
                {
                    Area      = "SUBSTANCES",
                    Setting   = "EXPORT_DATE",
                    DataValue = root.Attributes["exportDate"].Value
                });

                db.AppSettings.Add(new ApplicationSetting()
                {
                    Area      = "SUBSTANCES",
                    Setting   = "LAST_UPDATED",
                    DataValue = root.Attributes["lastUpdate"].Value
                });

                db.AppSettings.Add(new ApplicationSetting()
                {
                    Area      = "SUBSTANCES",
                    Setting   = "COUNT",
                    DataValue = root.Attributes["uniqueSustances"].Value
                });

                db.SaveChanges();

                //------------------------------------------------------------------------------------

                List <Entity> entities = new List <Entity>();

                XmlNodeList substanceNodes = xdoc.SelectNodes(xpath: "RegisteredSubstances/results/result");
                int         x = 0;
                foreach (XmlNode substanceNode in substanceNodes)
                {
                    Entity entity = new Entity();
                    entity.Active     = true;
                    entity.DateStamp  = DateTime.Now;
                    entity.EntityName = substanceNode.SelectSingleNode("name").InnerText;
                    entity.EntityType = 2;
                    entity.Id         = 0;
                    entity.OtherId    = substanceNode.SelectSingleNode("casNumber").InnerText;
                    entity.UserId     = 1;
                    entity.Properties = GetEntityProperties(substanceNode, xdoc);

                    entities.Add(entity);
                    x++;
                    if (x >= 1000)
                    {
                        db.Entities.AddRange(entities);
                        db.SaveChanges();
                        x        = 0;
                        entities = new List <Entity>();
                    }
                }

                db.Entities.AddRange(entities);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
        }
Beispiel #7
0
 public void CreateFacets(List <Facet> facetList)
 {
     db.AddRange(facetList);
     db.SaveChanges();
 }