/// <summary>
        /// GetAll fetch and returns queried list of items with specific fields from database.
        /// </summary>
        /// <param name="applicationClaimGroup"></param>
        /// <returns></returns>
        public async Task <List <ApplicationClaimGroup> > GetList(ApplicationClaimGroup applicationClaimGroup)
        {
            var applicationClaimGroups = new List <ApplicationClaimGroup>();
            ApplicationClaimGroup applicationClaimGroupItem = null;
            var parameters = new List <DbParameter>
            {
                base.GetParameter(BaseInfrastructure.CurrentUserIdParameterName, applicationClaimGroup.CreatedById)
            };

            using (var dataReader = await base.ExecuteReader(parameters, ClaimGroupInfrastructure.GetListStoredProcedureName, CommandType.StoredProcedure))
            {
                if (dataReader != null)
                {
                    while (dataReader.Read())
                    {
                        applicationClaimGroupItem = new ApplicationClaimGroup
                        {
                            ClaimGroupId               = dataReader.GetUnsignedIntegerValue(ClaimGroupInfrastructure.ClaimGroupIdColumnName),
                            ClaimGroupLabel            = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelColumnName),
                            ClaimGroupLabelTranslation = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelTranslationColumnName),
                            ClaimGroupCode             = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupCodeColumnName)
                        };

                        applicationClaimGroups.Add(applicationClaimGroupItem);
                    }
                    if (!dataReader.IsClosed)
                    {
                        dataReader.Close();
                    }
                }
            }

            return(applicationClaimGroups);
        }
        /// <summary>
        /// ConvertUpdate converts object of ClaimGroupResponseVM type to ApplicationClaimGroup.
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        private static ApplicationClaimGroup ConvertUpdate(this ClaimGroupResponseVM vm)
        {
            ApplicationClaimGroup model = new ApplicationClaimGroup
            {
                ClaimGroupId    = vm.ClaimGroupId,
                ClaimGroupLabel = vm.ClaimGroupLabel,
                ClaimGroupCode  = vm.ClaimGroupCode,
                Claims          = new List <ApplicationClaim>()
            };

            if (vm.Claims != null)
            {
                foreach (var claimItem in vm.Claims)
                {
                    model.Claims.Add(new ApplicationClaim
                    {
                        ClaimId      = claimItem.ClaimId,
                        ClaimGroupId = claimItem.ClaimGroupId,
                        ClaimLabel   = claimItem.ClaimLabel,
                        ClaimType    = claimItem.ClaimType,
                        ClaimCode    = claimItem.ClaimCode,
                        Active       = claimItem.Active
                    });
                }
            }

            return(model);
        }
        /// <summary>
        /// Convert converts object of ApplicationClaimGroup type to ClaimGroupResponseVM.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private static ClaimGroupResponseVM Convert(this ApplicationClaimGroup model, bool useLanguage)
        {
            ClaimGroupResponseVM claimGroupVM = new ClaimGroupResponseVM
            {
                ClaimGroupId    = model.ClaimGroupId,
                ClaimGroupLabel = useLanguage.GetLanguageText(model.ClaimGroupLabel, model.ClaimGroupLabelTranslation),
                ClaimGroupCode  = model.ClaimGroupCode,
                Claims          = new List <ClaimResponseVM>()
            };

            if (model.Claims != null)
            {
                foreach (var claimItem in model.Claims)
                {
                    claimGroupVM.Claims.Add(new ClaimResponseVM
                    {
                        ClaimId      = claimItem.ClaimId,
                        ClaimGroupId = claimItem.ClaimGroupId,
                        ClaimLabel   = useLanguage.GetLanguageText(claimItem.ClaimLabel, claimItem.ClaimLabelTranslation),
                        ClaimType    = claimItem.ClaimType,
                        ClaimCode    = claimItem.ClaimCode,
                        Active       = claimItem.Active
                    });
                }
            }

            return(claimGroupVM);
        }
        public async Task <List <ClaimGroupListResponseVM> > GetList([FromQuery] ClaimGroupRequestVM requestVM)
        {
            ApplicationClaimGroup        request  = requestVM.Convert();
            List <ApplicationClaimGroup> response = await this.ClaimGroupApplication.GetList(request);

            List <ClaimGroupListResponseVM> responseVM = response.ConvertList(base.UseDefaultLanguage);

            return(responseVM);
        }
        /// <summary>
        /// Activate activate/deactivate provided record and returns true if action was successfull.
        /// </summary>
        /// <param name="applicationClaimGroup"></param>
        /// <returns></returns>
        public async Task <bool> Activate(ApplicationClaimGroup applicationClaimGroup)
        {
            var parameters = new List <DbParameter>
            {
                base.GetParameter(ClaimGroupInfrastructure.ClaimGroupIdParameterName, applicationClaimGroup.ClaimGroupId),
                base.GetParameter(BaseInfrastructure.CurrentUserIdParameterName, applicationClaimGroup.CreatedById)
            };

            var returnValue = await base.ExecuteNonQuery(parameters, ClaimGroupInfrastructure.ActivateStoredProcedureName, CommandType.StoredProcedure);

            return(returnValue > 0);
        }
        ///// <summary>
        ///// Convert converts object of ApplicationClaim type to RequestApplicationClaimVM type.
        ///// </summary>
        ///// <param name="models"></param>
        ///// <returns></returns>
        //public static List<ClaimListRoleResponseVM> ConvertListByRole(this List<ApplicationClaim> models)
        //{
        //    List<ClaimListRoleResponseVM> vms = new List<ClaimListRoleResponseVM>();

        //    foreach (var model in models)
        //    {
        //        vms.Add(
        //            new ClaimListRoleResponseVM
        //            {
        //                ClaimId = model.ClaimId
        //            });
        //    }

        //    return vms;
        //}

        ///// <summary>
        ///// Convert converts object of ApplicationClaim type to RequestApplicationClaimVM type.
        ///// </summary>
        ///// <param name="models"></param>
        ///// <returns></returns>
        //public static List<ClaimListUserResponseVM> ConvertListByUser(this List<ApplicationClaim> models)
        //{
        //    List<ClaimListUserResponseVM> vms = new List<ClaimListUserResponseVM>();

        //    foreach (var model in models)
        //    {
        //        vms.Add(
        //            new ClaimListUserResponseVM
        //            {
        //                ClaimId = model.ClaimId,
        //                ClaimType = model.ClaimType,
        //                ClaimGroupLable = model.ClaimGroupLable
        //            });
        //    }

        //    return vms;
        //}

        ///// <summary>
        ///// Convert converts object of RequestApplicationClaimAllVM type to AllRequest ApplicationClaim.
        ///// </summary>
        ///// <param name="allRequestVM"></param>
        ///// <returns></returns>
        //public static AllRequest<ApplicationClaim> ConvertAll(this ApplicationClaimAllRequestVM allRequestVM)
        //{
        //    var allRequest = allRequestVM.Convert<ApplicationClaim>();

        //    allRequest.Data.ClaimId = allRequestVM.ClaimId;
        //    allRequest.Data.ClaimType = allRequestVM.ClaimType;
        //    allRequest.Data.CreatedById = allRequestVM.CurrentUserId;

        //    return allRequest;
        //}

        ///// <summary>
        ///// Convert converts object of AllResponse ApplicationClaim type to AllResponseVM ResponseApplicationClaimAllVM.
        ///// </summary>
        ///// <param name="allResponse"></param>
        ///// <returns></returns>
        //public static AllResponseVM<ApplicationClaimAllResponseVM> ConvertAll(this AllResponse<ApplicationClaim> allResponse)
        //{
        //    var allResponseVM = allResponse.Convert<ApplicationClaim, ApplicationClaimAllResponseVM>();

        //    allResponseVM.Data = new List<ApplicationClaimAllResponseVM>();

        //    foreach (var dataItem in allResponse.Data)
        //    {
        //        allResponseVM.Data.Add(
        //                new ApplicationClaimAllResponseVM
        //                {
        //                    ClaimId = dataItem.ClaimId,
        //                    ClaimType = dataItem.ClaimType
        //                }
        //            );
        //    }

        //    return allResponseVM;
        //}
        #endregion

        #region ApplicationClaimGroup
        /// <summary>
        /// Convert converts object of RequestApplicationClaimGroupVM type to ApplicationClaimGroup type.
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        public static ApplicationClaimGroup Convert(this ClaimGroupRequestVM vm)
        {
            var model = new ApplicationClaimGroup
            {
                ClaimGroupId    = vm.ClaimGroupId,
                ClaimGroupLabel = vm.ClaimGroupLabel,
                ClaimGroupCode  = vm.ClaimGroupCode,
                CreatedById     = vm.CurrentUserId
            };

            return(model);
        }
        /// <summary>
        /// Add adds new object in database and returns provided ObjectId.
        /// </summary>
        /// <param name="applicationClaimGroup"></param>
        /// <returns></returns>
        public async Task <uint> Add(ApplicationClaimGroup applicationClaimGroup)
        {
            var applicationClaimGroupIdParamter = base.GetParameterOut(ClaimGroupInfrastructure.ClaimGroupIdColumnName, SqlDbType.Int, applicationClaimGroup.ClaimGroupId);
            var parameters = new List <DbParameter>
            {
                applicationClaimGroupIdParamter,
                base.GetParameter(ClaimGroupInfrastructure.ClaimGroupLabelParameterName, applicationClaimGroup.ClaimGroupLabel),
                base.GetParameter(ClaimGroupInfrastructure.ClaimGroupCodeParameterName, applicationClaimGroup.ClaimGroupLabel),
                base.GetParameter(ClaimGroupInfrastructure.ClaimGroupCodeParameterName, applicationClaimGroup.ClaimGroupCode),
                base.GetParameter(BaseInfrastructure.CurrentUserIdParameterName, applicationClaimGroup.CreatedById)
            };
            //TODO: Add other parameters.

            await base.ExecuteNonQuery(parameters, ClaimGroupInfrastructure.AddStoredProcedureName, CommandType.StoredProcedure);

            applicationClaimGroup.ClaimGroupId = Convert.ToUInt32(applicationClaimGroupIdParamter.Value);

            return(applicationClaimGroup.ClaimGroupId);
        }
        /// <summary>
        /// Get fetch and returns queried item from database.
        /// </summary>
        /// <param name="applicationClaimGroup"></param>
        /// <returns></returns>
        public async Task <ApplicationClaimGroup> Get(ApplicationClaimGroup applicationClaimGroup)
        {
            ApplicationClaimGroup ApplicationClaimGroupItem = null;
            var parameters = new List <DbParameter>
            {
                base.GetParameter(ClaimGroupInfrastructure.ClaimGroupIdParameterName, applicationClaimGroup.ClaimGroupId),
                base.GetParameter(BaseInfrastructure.CurrentUserIdParameterName, applicationClaimGroup.CreatedById)
            };

            using (var dataReader = await base.ExecuteReader(parameters, ClaimGroupInfrastructure.GetStoredProcedureName, CommandType.StoredProcedure))
            {
                if (dataReader != null && dataReader.HasRows)
                {
                    if (dataReader.Read())
                    {
                        ApplicationClaimGroupItem = new ApplicationClaimGroup
                        {
                            ClaimGroupId               = dataReader.GetUnsignedIntegerValue(ClaimGroupInfrastructure.ClaimGroupIdColumnName),
                            ClaimGroupLabel            = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelColumnName),
                            ClaimGroupLabelTranslation = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelTranslationColumnName),
                            ClaimGroupCode             = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupCodeColumnName),
                            CreatedById    = dataReader.GetUnsignedIntegerValueNullable(BaseInfrastructure.CreatedByIdColumnName),
                            CreatedByName  = dataReader.GetStringValue(BaseInfrastructure.CreatedByNameColumnName),
                            CreatedDate    = dataReader.GetDateTimeValueNullable(BaseInfrastructure.CreatedDateColumnName),
                            ModifiedById   = dataReader.GetUnsignedIntegerValueNullable(BaseInfrastructure.ModifiedByIdColumnName),
                            ModifiedByName = dataReader.GetStringValue(BaseInfrastructure.ModifiedByNameColumnName),
                            ModifiedDate   = dataReader.GetDateTimeValueNullable(BaseInfrastructure.ModifiedDateColumnName)
                        };
                    }
                    if (!dataReader.IsClosed)
                    {
                        dataReader.Close();
                    }
                }
            }

            return(ApplicationClaimGroupItem);
        }
        /// <summary>
        /// GetAll executes provided stored procedure with provided parameters.
        /// </summary>
        /// <param name="applicationClaimGroup"></param>
        /// <param name="storedProcedureName"></param>
        /// <returns></returns>
        private async Task <AllResponse <ApplicationClaimGroup> > GetAll(AllRequest <ApplicationClaimGroup> applicationClaimGroup, string storedProcedureName)
        {
            var result = new AllResponse <ApplicationClaimGroup>
            {
                Data          = new List <ApplicationClaimGroup>(),
                Offset        = applicationClaimGroup.Offset,
                PageSize      = applicationClaimGroup.PageSize,
                SortColumn    = applicationClaimGroup.SortColumn,
                SortAscending = applicationClaimGroup.SortAscending
            };

            ApplicationClaimGroup applicationClaimGroupItem = null;
            ApplicationClaimGroup currentGroup         = null;
            ApplicationClaim      applicationClaimItem = null;
            var totalRecordParamter = base.GetParameterOut(BaseInfrastructure.TotalRecordParameterName, SqlDbType.Int, result.TotalRecord);
            var parameters          = new List <DbParameter>
            {
                totalRecordParamter,
                base.GetParameter(BaseInfrastructure.OffsetParameterName, applicationClaimGroup.Offset),
                base.GetParameter(BaseInfrastructure.PageSizeParameterName, applicationClaimGroup.PageSize),
                base.GetParameter(BaseInfrastructure.SortColumnParameterName, applicationClaimGroup.SortColumn),
                base.GetParameter(BaseInfrastructure.SortAscendingParameterName, applicationClaimGroup.SortAscending),
                base.GetParameter(BaseInfrastructure.CurrentUserIdParameterName, applicationClaimGroup.Data.CreatedById)
            };

            //TODO: Add other parameters.

            using (var dataReader = await base.ExecuteReader(parameters, storedProcedureName, CommandType.StoredProcedure))
            {
                if (dataReader != null && dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        applicationClaimGroupItem = new ApplicationClaimGroup
                        {
                            ClaimGroupId               = dataReader.GetUnsignedIntegerValue(ClaimGroupInfrastructure.ClaimGroupIdColumnName),
                            ClaimGroupLabel            = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelColumnName),
                            ClaimGroupLabelTranslation = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelTranslationColumnName),
                            ClaimGroupCode             = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupCodeColumnName),
                            Claims = new List <ApplicationClaim>()
                        };
                        //TODO: Add other Columns.

                        result.Data.Add(applicationClaimGroupItem);
                    }

                    if (dataReader.NextResult())
                    {
                        while (dataReader.Read())
                        {
                            applicationClaimItem = new ApplicationClaim
                            {
                                ClaimId               = dataReader.GetUnsignedIntegerValue(ClaimInfrastructure.ClaimIdColumnName),
                                ClaimGroupId          = dataReader.GetUnsignedIntegerValue(ClaimInfrastructure.ClaimGroupIdColumnName),
                                ClaimType             = dataReader.GetStringValue(ClaimInfrastructure.ClaimTypeColumnName),
                                ClaimLabel            = dataReader.GetStringValue(ClaimInfrastructure.ClaimLabelColumnName),
                                ClaimLabelTranslation = dataReader.GetStringValue(ClaimInfrastructure.ClaimLabelTranslationColumnName),
                                ClaimCode             = dataReader.GetStringValue(ClaimInfrastructure.ClaimCodeColumnName),
                                Active = dataReader.GetBooleanValue(ClaimInfrastructure.ActiveColumnName)
                            };

                            if (currentGroup == null || currentGroup.ClaimGroupId != applicationClaimItem.ClaimGroupId)
                            {
                                currentGroup = result.Data.FirstOrDefault(c => c.ClaimGroupId == applicationClaimItem.ClaimGroupId);
                            }

                            currentGroup?.Claims.Add(applicationClaimItem);
                        }
                    }

                    if (!dataReader.IsClosed)
                    {
                        dataReader.Close();
                    }

                    result.TotalRecord = Convert.ToUInt32(totalRecordParamter.Value);
                }
            }

            return(result);
        }
 /// <summary>
 /// GetAll calls ClaimGroupInfrastructure to fetch and returns queried list of items with specific fields from database.
 /// </summary>
 /// <param name="applicationClaimGroup"></param>
 /// <returns></returns>
 public async Task <List <ApplicationClaimGroup> > GetList(ApplicationClaimGroup applicationClaimGroup)
 {
     return(await this.ClaimGroupInfrastructure.GetList(applicationClaimGroup));
 }
 /// <summary>
 /// Activate calls ClaimGroupInfrastructure to activate/deactivate provided record and returns true if action was successfull.
 /// </summary>
 /// <param name="applicationClaimGroup"></param>
 /// <returns></returns>
 public async Task <bool> Activate(ApplicationClaimGroup applicationClaimGroup)
 {
     return(await this.ClaimGroupInfrastructure.Activate(applicationClaimGroup));
 }
 /// <summary>
 /// Add calls ClaimGroupInfrastructure to adds new object in database and returns provided ObjectId.
 /// </summary>
 /// <param name="applicationClaimGroup"></param>
 /// <returns></returns>
 public async Task <uint> Add(ApplicationClaimGroup applicationClaimGroup)
 {
     return(await this.ClaimGroupInfrastructure.Add(applicationClaimGroup));
 }
Exemple #13
0
        /// <summary>
        /// Get fetch and returns queried item from database.
        /// </summary>
        /// <param name="applicationRole"></param>
        /// <returns></returns>
        public async Task <ApplicationRole> Get(ApplicationRole applicationRole)
        {
            ApplicationRole       applicationRoleItem       = null;
            ApplicationClaimGroup applicationClaimGroupItem = null;
            ApplicationClaimGroup currentGroup         = null;
            ApplicationClaim      applicationClaimItem = null;
            var parameters = new List <DbParameter>
            {
                base.GetParameter(RoleInfrastructure.RoleIdParameterName, applicationRole.RoleId),
                base.GetParameter(BaseInfrastructure.CurrentUserIdParameterName, applicationRole.CreatedById)
            };

            using (var dataReader = await base.ExecuteReader(parameters, RoleInfrastructure.GetStoredProcedureName, CommandType.StoredProcedure))
            {
                if (dataReader != null && dataReader.HasRows)
                {
                    if (dataReader.Read())
                    {
                        applicationRoleItem = new ApplicationRole
                        {
                            RoleId              = dataReader.GetUnsignedIntegerValue(RoleInfrastructure.RoleIdColumnName),
                            RoleName            = dataReader.GetStringValue(RoleInfrastructure.RoleNameColumnName),
                            RoleNameTranslation = dataReader.GetStringValue(RoleInfrastructure.RoleNameTranslationColumnName),
                            RoleNameCode        = dataReader.GetStringValue(RoleInfrastructure.RoleNameCodeColumnName),
                            CreatedById         = dataReader.GetUnsignedIntegerValue(BaseInfrastructure.CreatedByIdColumnName),
                            CreatedDate         = dataReader.GetDateTimeValueNullable(BaseInfrastructure.CreatedDateColumnName),
                            ModifiedById        = dataReader.GetUnsignedIntegerValue(BaseInfrastructure.ModifiedByIdColumnName),
                            ModifiedDate        = dataReader.GetDateTimeValueNullable(BaseInfrastructure.ModifiedDateColumnName),
                            Active              = dataReader.GetBooleanValue(BaseInfrastructure.ActiveColumnName),
                            ClaimGroups         = new List <ApplicationClaimGroup>()
                        };

                        if (dataReader.NextResult())
                        {
                            while (dataReader.Read())
                            {
                                applicationClaimGroupItem = new ApplicationClaimGroup
                                {
                                    ClaimGroupId               = dataReader.GetUnsignedIntegerValue(ClaimGroupInfrastructure.ClaimGroupIdColumnName),
                                    ClaimGroupLabel            = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelColumnName),
                                    ClaimGroupLabelTranslation = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupLabelTranslationColumnName),
                                    ClaimGroupCode             = dataReader.GetStringValue(ClaimGroupInfrastructure.ClaimGroupCodeColumnName),
                                    Claims = new List <ApplicationClaim>()
                                };

                                applicationRoleItem.ClaimGroups.Add(applicationClaimGroupItem);
                            }

                            if (dataReader.NextResult())
                            {
                                while (dataReader.Read())
                                {
                                    applicationClaimItem = new ApplicationClaim
                                    {
                                        ClaimId               = dataReader.GetUnsignedIntegerValue(ClaimInfrastructure.ClaimIdColumnName),
                                        ClaimGroupId          = dataReader.GetUnsignedIntegerValue(ClaimInfrastructure.ClaimGroupIdColumnName),
                                        ClaimType             = dataReader.GetStringValue(ClaimInfrastructure.ClaimTypeColumnName),
                                        ClaimLabel            = dataReader.GetStringValue(ClaimInfrastructure.ClaimLabelColumnName),
                                        ClaimLabelTranslation = dataReader.GetStringValue(ClaimInfrastructure.ClaimLabelTranslationColumnName),
                                        ClaimCode             = dataReader.GetStringValue(ClaimInfrastructure.ClaimCodeColumnName),
                                        Active = dataReader.GetBooleanValue(BaseInfrastructure.ActiveColumnName)
                                    };

                                    if (currentGroup == null || currentGroup.ClaimGroupId != applicationClaimItem.ClaimGroupId)
                                    {
                                        currentGroup = applicationRoleItem.ClaimGroups.FirstOrDefault(c => c.ClaimGroupId == applicationClaimItem.ClaimGroupId);
                                    }

                                    currentGroup?.Claims.Add(applicationClaimItem);
                                }
                            }
                        }
                    }

                    if (!dataReader.IsClosed)
                    {
                        dataReader.Close();
                    }
                }

                return(applicationRoleItem);
            }
        }