Example #1
0
        private async Task SaveReference(KpiGeneral KpiGeneral)
        {
            await DataContext.KpiGeneralContentKpiPeriodMapping
            .Where(x => x.KpiGeneralContent.KpiGeneralId == KpiGeneral.Id)
            .DeleteFromQueryAsync();

            await DataContext.KpiGeneralContent
            .Where(x => x.KpiGeneralId == KpiGeneral.Id)
            .DeleteFromQueryAsync();

            List <KpiGeneralContentDAO> KpiGeneralContentDAOs = new List <KpiGeneralContentDAO>();
            List <KpiGeneralContentKpiPeriodMappingDAO> KpiGeneralContentKpiCriteriaItemMappingDAOs = new List <KpiGeneralContentKpiPeriodMappingDAO>();

            if (KpiGeneral.KpiGeneralContents != null)
            {
                KpiGeneral.KpiGeneralContents.ForEach(x => x.RowId = Guid.NewGuid());
                foreach (KpiGeneralContent KpiGeneralContent in KpiGeneral.KpiGeneralContents)
                {
                    KpiGeneralContentDAO KpiGeneralContentDAO = new KpiGeneralContentDAO();
                    KpiGeneralContentDAO.Id                   = KpiGeneralContent.Id;
                    KpiGeneralContentDAO.KpiGeneralId         = KpiGeneral.Id;
                    KpiGeneralContentDAO.KpiCriteriaGeneralId = KpiGeneralContent.KpiCriteriaGeneralId;
                    KpiGeneralContentDAO.RowId                = KpiGeneralContent.RowId;
                    KpiGeneralContentDAO.StatusId             = KpiGeneralContent.StatusId;
                    KpiGeneralContentDAOs.Add(KpiGeneralContentDAO);
                }
                await DataContext.KpiGeneralContent.BulkMergeAsync(KpiGeneralContentDAOs);


                foreach (KpiGeneralContent KpiGeneralContent in KpiGeneral.KpiGeneralContents)
                {
                    KpiGeneralContent.Id = KpiGeneralContentDAOs.Where(x => x.RowId == KpiGeneralContent.RowId).Select(x => x.Id).FirstOrDefault();
                    if (KpiGeneralContent.KpiGeneralContentKpiPeriodMappings != null)
                    {
                        foreach (KpiGeneralContentKpiPeriodMapping KpiGeneralContentKpiPeriodMapping in KpiGeneralContent.KpiGeneralContentKpiPeriodMappings)
                        {
                            KpiGeneralContentKpiPeriodMappingDAO KpiGeneralContentKpiCriteriaItemMappingDAO = new KpiGeneralContentKpiPeriodMappingDAO
                            {
                                KpiGeneralContentId = KpiGeneralContent.Id,
                                KpiPeriodId         = KpiGeneralContentKpiPeriodMapping.KpiPeriodId,
                                Value = KpiGeneralContentKpiPeriodMapping.Value
                            };
                            KpiGeneralContentKpiCriteriaItemMappingDAOs.Add(KpiGeneralContentKpiCriteriaItemMappingDAO);
                        }
                    }
                }

                await DataContext.KpiGeneralContentKpiPeriodMapping.BulkMergeAsync(KpiGeneralContentKpiCriteriaItemMappingDAOs);
            }
        }
        public async Task <bool> Create(KpiGeneralContent KpiGeneralContent)
        {
            KpiGeneralContentDAO KpiGeneralContentDAO = new KpiGeneralContentDAO();

            KpiGeneralContentDAO.Id                   = KpiGeneralContent.Id;
            KpiGeneralContentDAO.KpiGeneralId         = KpiGeneralContent.KpiGeneralId;
            KpiGeneralContentDAO.KpiCriteriaGeneralId = KpiGeneralContent.KpiCriteriaGeneralId;
            KpiGeneralContentDAO.StatusId             = KpiGeneralContent.StatusId;
            DataContext.KpiGeneralContent.Add(KpiGeneralContentDAO);
            await DataContext.SaveChangesAsync();

            KpiGeneralContent.Id = KpiGeneralContentDAO.Id;
            await SaveReference(KpiGeneralContent);

            return(true);
        }
        public async Task <bool> BulkMerge(List <KpiGeneralContent> KpiGeneralContents)
        {
            List <KpiGeneralContentDAO> KpiGeneralContentDAOs = new List <KpiGeneralContentDAO>();

            foreach (KpiGeneralContent KpiGeneralContent in KpiGeneralContents)
            {
                KpiGeneralContentDAO KpiGeneralContentDAO = new KpiGeneralContentDAO();
                KpiGeneralContentDAO.Id                   = KpiGeneralContent.Id;
                KpiGeneralContentDAO.KpiGeneralId         = KpiGeneralContent.KpiGeneralId;
                KpiGeneralContentDAO.KpiCriteriaGeneralId = KpiGeneralContent.KpiCriteriaGeneralId;
                KpiGeneralContentDAO.StatusId             = KpiGeneralContent.StatusId;
                KpiGeneralContentDAOs.Add(KpiGeneralContentDAO);
            }
            await DataContext.BulkMergeAsync(KpiGeneralContentDAOs);

            return(true);
        }
        public async Task <bool> Update(KpiGeneralContent KpiGeneralContent)
        {
            KpiGeneralContentDAO KpiGeneralContentDAO = DataContext.KpiGeneralContent.Where(x => x.Id == KpiGeneralContent.Id).FirstOrDefault();

            if (KpiGeneralContentDAO == null)
            {
                return(false);
            }
            KpiGeneralContentDAO.Id                   = KpiGeneralContent.Id;
            KpiGeneralContentDAO.KpiGeneralId         = KpiGeneralContent.KpiGeneralId;
            KpiGeneralContentDAO.KpiCriteriaGeneralId = KpiGeneralContent.KpiCriteriaGeneralId;
            KpiGeneralContentDAO.StatusId             = KpiGeneralContent.StatusId;
            await DataContext.SaveChangesAsync();

            await SaveReference(KpiGeneralContent);

            return(true);
        }