Exemple #1
0
        public int SaveAtivity(Activity activity, iatiactivity iatiActivity, tblFundSource fundSource)
        {


            return SaveAtivities(new List<Activity> { activity }, new List<iatiactivity> { iatiActivity }, fundSource);
        }
Exemple #2
0
        private List<ProjectFieldMapModel> PrepareMappedActivities(List<iatiactivity> iatiActivities, Activity a, AimsDAL aimsDAL)
        {
            //step 1: project structure
            var iactivities = new List<iatiactivity>();
            if (a.Hierarchy == 1)
                iactivities = ImportLogic.LoadH1ActivitiesWithChild(iatiActivities); // here pass all activities to find out their child activities
            else
                iactivities = ImportLogic.LoadH2ActivitiesWithParent(iatiActivities);

            //step 2: get mapped iatiActivity and aimsProject
            var iatiActivity = iactivities.Find(f => f.IatiIdentifier == a.IatiIdentifier);
            // SetExchangedValues
            SetExchangedValues(iatiActivity);
            iatiActivity.childActivities.ForEach(ra => SetExchangedValues(ra));

            var aimsProject = new iatiactivity();
            if (a.ProjectId > 0)
            {
                aimsProject = aimsDAL.GetAIMSProjectInIATIFormat(a.ProjectId);
            }
            else if (a.MappedProjectId > 0) //for co-finance projects
            {
                aimsProject = aimsDAL.GetAIMSProjectInIATIFormat(a.MappedProjectId);
            }

            //step 3: get general preference
            var generalPreference = GetFieldMappingPreferenceGeneral(a.OrgId);

            //step 4: create a ProjectFieldMapModel using iatiActivity, aimsProject and generalPreference
            var ProjectFieldMapModel = new ProjectFieldMapModel(iatiActivity, aimsProject, generalPreference);

            //step 5: SetFieldMappingPreferences
            var ProjectFieldMapModels = new List<ProjectFieldMapModel>(); // here we make a list just to use existing method (e.g existing method require a List parameter)
            ProjectFieldMapModels.Add(ProjectFieldMapModel);

            ImportLogic.SetFieldMappingPreferences(ProjectFieldMapModels, ProjectFieldMapModel);
            return ProjectFieldMapModels;
        }
Exemple #3
0
        /// <summary>
        /// Save Data To DB
        /// </summary>
        /// <param name="returnResult2"></param>
        private void SaveToDB(tblFundSource fundSource, AIMS_BD_IATI.Library.Parser.ParserIATIv2.iatiactivity[] iatiactivityArray)
        {

            int counter = 1;
            int successfullySavedActivityCounter = 0;
            int totalActivity = iatiactivityArray.Count();

            Logger.Write("INFO: " + "Total Activity found: " + totalActivity);
            Console.WriteLine();
            if (totalActivity > 0)
            {
                foreach (var iatiactivityItem in iatiactivityArray)
                {
                    try
                    {
                        var Activity = new Activity();

                        Activity.OrgId = Activity.AssignedOrgId = fundSource.IATICode;// iatiactivityItem.reportingorg?.@ref;
                        Activity.IatiIdentifier = iatiactivityItem.IatiIdentifier;
                        Activity.Hierarchy = iatiactivityItem.hierarchy;

                        using (StringWriter ww = new StringWriter())
                        {
                            iatiactivitySerealizer.Serialize(ww, iatiactivityItem);
                            Activity.IatiActivity = ww.ToString();
                        }

                        successfullySavedActivityCounter += new AimsDbIatiDAL().SaveAtivity(Activity, iatiactivityItem, fundSource) == 1 ? 1 : 0;

                        Console.Write("\r Activity Counter: {0}   ", counter++);

                    }
                    catch (DbEntityValidationException ex)
                    {
                        string messages = "";
                        foreach (var validationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                messages += string.Format("\nProperty: {0} Error: {1}",
                                                        validationError.PropertyName,
                                                        validationError.ErrorMessage);
                            }
                        }
                        Logger.WriteToDbAndFile(ex, LogType.ValidationError, fundSource.IATICode, iatiactivityItem.IatiIdentifier, messages);

                    }
                    catch (Exception ex)
                    {
                        Logger.WriteToDbAndFile(ex, LogType.Error, fundSource.IATICode, iatiactivityItem.IatiIdentifier);
                    }

                }

                Logger.Write("INFO: " + successfullySavedActivityCounter + " activities are stored in Database");
            }
        }