Ejemplo n.º 1
0
        public virtual async Task <EFReturnValue> SaveHeaderDetailAsync <T, T1, T2, T3, T4, T5>(T tblHeader, string idReferenceColName, T1 tblDetail1, T2 tblDetail2, T3 tblDetail3, T4 tblDetail4, T5 tblDetail5)
            where T : class
            where T1 : class
            where T2 : class
            where T3 : class
            where T4 : class
            where T5 : class
        {
            object objIDColumnHeader = null; eFReturn = new EFReturnValue {
                IsSuccessConnection = false, IsSuccessQuery = false, ErrorMessage = ErrorMessage.EntityCannotBeNull, ReturnValue = null
            };
            bool resultDetail = false;

            if (tblHeader != null & !string.IsNullOrEmpty(idReferenceColName) & tblDetail1 != null)
            {
                RepoSaveAsync repoSave = new RepoSaveAsync();
                tblHeader = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T>(tblHeader);
                var saveMainTable = await repoSave.SaveAsync <T>(tblHeader).ConfigureAwait(false); // Safe first in main table

                if (saveMainTable.IsSuccessConnection & saveMainTable.IsSuccessQuery)
                {
                    var propIdColumnHeader = ColumnPropGet.GetInstance.GetIdentityColumnProps <T>();
                    objIDColumnHeader = propIdColumnHeader != null?propIdColumnHeader.GetValue(tblHeader) : null;

                    if (objIDColumnHeader != null)
                    {
                        ColumnPropSet.GetInstance.SetColValue <T1>(tblDetail1, idReferenceColName, objIDColumnHeader); // set value ref id to tbldetails
                        ColumnPropSet.GetInstance.SetColValue <T2>(tblDetail2, idReferenceColName, objIDColumnHeader); // set value ref id to tbldetails
                        ColumnPropSet.GetInstance.SetColValue <T3>(tblDetail3, idReferenceColName, objIDColumnHeader); // set value ref id to tbldetails
                        ColumnPropSet.GetInstance.SetColValue <T4>(tblDetail4, idReferenceColName, objIDColumnHeader); // set value ref id to tbldetails
                        ColumnPropSet.GetInstance.SetColValue <T5>(tblDetail5, idReferenceColName, objIDColumnHeader); // set value ref id to tbldetails

                        tblDetail1 = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T1>(tblDetail1);
                        tblDetail2 = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T2>(tblDetail2);
                        tblDetail3 = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T3>(tblDetail3);
                        tblDetail4 = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T4>(tblDetail4);
                        tblDetail5 = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T5>(tblDetail5);

                        var saveDetailTable = await repoSave.SaveAsync <T1, T2, T3, T4, T5>(tblDetail1, tblDetail2, tblDetail3, tblDetail4, tblDetail5).ConfigureAwait(false);//save to T1

                        if (resultDetail)
                        {
                            eFReturn = eFReturn.SetEFReturnValue(eFReturn, true, 1, tblDetail1, tblDetail2, tblDetail3, tblDetail4, tblDetail5);
                        }
                        else
                        {
                            RepoDeleteAsync repoDelete = new RepoDeleteAsync();
                            await repoDelete.DeleteAsync <T>(tblHeader).ConfigureAwait(false);

                            eFReturn = eFReturn.SetEFReturnValue(eFReturn, false, 0, ErrorMessage.SaveHeaderDetailFailed);
                        }
                    }
                }
            }
            return(eFReturn);
        }
        public virtual async Task <EFReturnValue> SaveHeaderDetailListAsync <T, T1, T2>(T tblHeader, string idReferenceColName, List <T1> listTblDetail1, List <T2> listTblDetail2)
            where T : class
            where T1 : class
            where T2 : class
        {
            object objIDColumnHeader = null; eFReturn = new EFReturnValue {
                IsSuccessConnection = false, IsSuccessQuery = false, ErrorMessage = ErrorMessage.EntityCannotBeNull, ReturnValue = null
            };

            if (tblHeader != null & !string.IsNullOrEmpty(idReferenceColName) & listTblDetail1 != null)
            {
                RepoSaveAsync repoSave = new RepoSaveAsync();
                tblHeader = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T>(tblHeader);
                var saveMainTable = await repoSave.SaveAsync <T>(tblHeader).ConfigureAwait(false); // Safe first in main table

                RepoSaveListAsync repoSaveList = new RepoSaveListAsync();
                if (saveMainTable.IsSuccessConnection & saveMainTable.IsSuccessQuery)
                {
                    var propIdColumnHeader = ColumnPropGet.GetInstance.GetIdentityColumnProps <T>();
                    objIDColumnHeader = propIdColumnHeader != null?propIdColumnHeader.GetValue(tblHeader) : null;

                    if (objIDColumnHeader != null)
                    {
                        ColumnPropSet.GetInstance.SetColValue <List <T1> >(listTblDetail1, idReferenceColName, objIDColumnHeader); // set value ref id to tbldetails
                        ColumnPropSet.GetInstance.SetColValue <List <T2> >(listTblDetail2, idReferenceColName, objIDColumnHeader); // set value ref id to tbldetails

                        listTblDetail1 = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T1>(listTblDetail1);
                        listTblDetail2 = EntityPreparationBantuan.GetInstance.DictEntityPreparation["save"].SetPreparationEntity <T2>(listTblDetail2);

                        var saveDetailTable = await repoSaveList.SaveListAsync <T1, T2>(listTblDetail1, listTblDetail2).ConfigureAwait(false);//save to T1 & others

                        if (saveDetailTable.IsSuccessConnection & saveDetailTable.IsSuccessQuery)
                        {
                            eFReturn = eFReturn.SetEFReturnValue(eFReturn, true, 1, listTblDetail1);
                        }
                        else
                        {
                            eFReturn = eFReturn.SetEFReturnValue(eFReturn, false, 0, ErrorMessage.SaveHeaderDetailFailed);
                            RepoDeleteAsync repoDelete = new RepoDeleteAsync();
                            await repoDelete.DeleteAsync <T>(tblHeader).ConfigureAwait(false);
                        }
                    }
                }
            }
            return(eFReturn);
        }