예제 #1
0
        public async Task <bool> Create(KpiGeneral KpiGeneral)
        {
            KpiGeneralDAO KpiGeneralDAO = new KpiGeneralDAO();

            KpiGeneralDAO.Id             = KpiGeneral.Id;
            KpiGeneralDAO.OrganizationId = KpiGeneral.OrganizationId;
            KpiGeneralDAO.EmployeeId     = KpiGeneral.EmployeeId;
            KpiGeneralDAO.KpiYearId      = KpiGeneral.KpiYearId;
            KpiGeneralDAO.StatusId       = KpiGeneral.StatusId;
            KpiGeneralDAO.CreatorId      = KpiGeneral.CreatorId;
            KpiGeneralDAO.CreatedAt      = StaticParams.DateTimeNow;
            KpiGeneralDAO.UpdatedAt      = StaticParams.DateTimeNow;
            DataContext.KpiGeneral.Add(KpiGeneralDAO);
            await DataContext.SaveChangesAsync();

            KpiGeneral.Id = KpiGeneralDAO.Id;
            await SaveReference(KpiGeneral);

            return(true);
        }
예제 #2
0
        public async Task <bool> Update(KpiGeneral KpiGeneral)
        {
            KpiGeneralDAO KpiGeneralDAO = DataContext.KpiGeneral.Where(x => x.Id == KpiGeneral.Id).FirstOrDefault();

            if (KpiGeneralDAO == null)
            {
                return(false);
            }
            KpiGeneralDAO.Id             = KpiGeneral.Id;
            KpiGeneralDAO.OrganizationId = KpiGeneral.OrganizationId;
            KpiGeneralDAO.EmployeeId     = KpiGeneral.EmployeeId;
            KpiGeneralDAO.KpiYearId      = KpiGeneral.KpiYearId;
            KpiGeneralDAO.StatusId       = KpiGeneral.StatusId;
            KpiGeneralDAO.CreatorId      = KpiGeneral.CreatorId;
            KpiGeneralDAO.UpdatedAt      = StaticParams.DateTimeNow;
            await DataContext.SaveChangesAsync();

            await SaveReference(KpiGeneral);

            return(true);
        }
예제 #3
0
        public async Task <bool> BulkMerge(List <KpiGeneral> KpiGenerals)
        {
            List <KpiGeneralDAO> KpiGeneralDAOs = new List <KpiGeneralDAO>();

            foreach (KpiGeneral KpiGeneral in KpiGenerals)
            {
                KpiGeneralDAO KpiGeneralDAO = new KpiGeneralDAO();
                KpiGeneralDAO.Id             = KpiGeneral.Id;
                KpiGeneralDAO.OrganizationId = KpiGeneral.OrganizationId;
                KpiGeneralDAO.EmployeeId     = KpiGeneral.EmployeeId;
                KpiGeneralDAO.KpiYearId      = KpiGeneral.KpiYearId;
                KpiGeneralDAO.StatusId       = KpiGeneral.StatusId;
                KpiGeneralDAO.CreatorId      = KpiGeneral.CreatorId;
                KpiGeneralDAO.CreatedAt      = StaticParams.DateTimeNow;
                KpiGeneralDAO.UpdatedAt      = StaticParams.DateTimeNow;
                KpiGeneralDAO.RowId          = KpiGeneral.RowId;
                KpiGeneralDAOs.Add(KpiGeneralDAO);
            }
            await DataContext.BulkMergeAsync(KpiGeneralDAOs);

            var KpiGeneralIds = KpiGeneralDAOs.Select(x => x.Id).ToList();
            await DataContext.KpiGeneralContentKpiPeriodMapping
            .Where(x => KpiGeneralIds.Contains(x.KpiGeneralContent.KpiGeneralId))
            .DeleteFromQueryAsync();

            await DataContext.KpiGeneralContent
            .Where(x => KpiGeneralIds.Contains(x.KpiGeneralId))
            .DeleteFromQueryAsync();

            var KpiGeneralContentDAOs = new List <KpiGeneralContentDAO>();

            foreach (var KpiGeneral in KpiGenerals)
            {
                KpiGeneral.Id = KpiGeneralDAOs.Where(x => x.RowId == KpiGeneral.RowId).Select(x => x.Id).FirstOrDefault();
                if (KpiGeneral.KpiGeneralContents != null && KpiGeneral.KpiGeneralContents.Any())
                {
                    var listContent = KpiGeneral.KpiGeneralContents.Select(x => new KpiGeneralContentDAO
                    {
                        KpiCriteriaGeneralId = x.KpiCriteriaGeneralId, // KpiCriteriaGeneralId da co san map tu frontend xuong
                        KpiGeneralId         = KpiGeneral.Id,
                        KpiGeneralContentKpiPeriodMappings = x.KpiGeneralContentKpiPeriodMappings.Select(x => new KpiGeneralContentKpiPeriodMappingDAO
                        {
                            KpiPeriodId         = x.KpiPeriodId, // map tu du lieu bang mapping sang bang KpiGeneral sang KpiGeneralContentDAOs
                            Value               = x.Value,
                            KpiGeneralContentId = 0,             // se duoc gan luc sau
                        }).ToList(),
                        RowId    = Guid.NewGuid(),
                        StatusId = x.StatusId,
                    }).ToList();
                    KpiGeneralContentDAOs.AddRange(listContent);
                }
            }
            await DataContext.BulkMergeAsync(KpiGeneralContentDAOs);


            var KpiGeneralContentKpiPeriodMappingDAOs = new List <KpiGeneralContentKpiPeriodMappingDAO>();

            foreach (var KpiGeneralContent in KpiGeneralContentDAOs)
            {
                KpiGeneralContent.Id = KpiGeneralContentDAOs.Where(x => x.RowId == KpiGeneralContent.RowId).Select(x => x.Id).FirstOrDefault(); // get Id dua vao RowId
                if (KpiGeneralContent.KpiGeneralContentKpiPeriodMappings != null && KpiGeneralContent.KpiGeneralContentKpiPeriodMappings.Any())
                {
                    var listMappings = KpiGeneralContent.KpiGeneralContentKpiPeriodMappings.Select(x => new KpiGeneralContentKpiPeriodMappingDAO
                    {
                        KpiPeriodId         = x.KpiPeriodId,
                        Value               = x.Value,
                        KpiGeneralContentId = KpiGeneralContent.Id
                    }).ToList();
                    KpiGeneralContentKpiPeriodMappingDAOs.AddRange(listMappings);
                }
            }

            await DataContext.BulkMergeAsync(KpiGeneralContentKpiPeriodMappingDAOs);

            return(true);
        }