Exemplo n.º 1
0
        public ResultDTO UpdateRole(int RoleId, BusinessEntities.RoleEntity roleEntity)
        {
            var result = new ResultDTO {
                IsSuccess = false
            };

            if (roleEntity != null)
            {
                var isExist = _unitOfWork.RoleRepository.GetManyQueryable(c => c.RoleName.ToLower() == roleEntity.RoleName.ToLower() && c.OrganizationLevelId == roleEntity.OrganizationLevelId).Count() > 0;
                if (!isExist)
                {
                    using (var scope = new TransactionScope())
                    {
                        var role = _unitOfWork.RoleRepository.GetByID(RoleId);
                        if (roleEntity != null)
                        {
                            role.RoleId              = roleEntity.RoleId;
                            role.RoleName            = roleEntity.RoleName;
                            role.OrganizationLevelId = roleEntity.OrganizationLevelId;
                            role.IsActive            = roleEntity.IsActive;
                            role.ModifiedBy          = roleEntity.ModifiedBy;
                            role.ModifiedOn          = DateTime.Now;

                            _unitOfWork.RoleRepository.Update(role);
                            _unitOfWork.Save();
                            scope.Complete();

                            result.IsSuccess = true;
                            result.Message   = "Updated Successfully";
                        }
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = "Role already exist";
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public ResultDTO CreateRole(BusinessEntities.RoleEntity roleEntity)
        {
            var result = new ResultDTO {
                IsSuccess = false
            };

            var isExist = _unitOfWork.RoleRepository.GetManyQueryable(c => c.RoleName.ToLower() == roleEntity.RoleName.ToLower() && c.OrganizationLevelId == roleEntity.OrganizationLevelId).Count() > 0;

            if (!isExist)
            {
                using (var scope = new TransactionScope())
                {
                    var role = new Role
                    {
                        RoleName            = roleEntity.RoleName,
                        OrganizationLevelId = roleEntity.OrganizationLevelId,
                        IsActive            = true,
                        CreatedBy           = roleEntity.CreatedBy,
                        CreatedOn           = DateTime.Now,
                        ModifiedBy          = roleEntity.CreatedBy,
                        ModifiedOn          = DateTime.Now,
                    };
                    _unitOfWork.RoleRepository.Insert(role);
                    _unitOfWork.Save();
                    scope.Complete();

                    result.IsSuccess = true;
                    result.Message   = "Added Successfully";
                }
            }
            else
            {
                result.IsSuccess = false;
                result.Message   = "Role already exist";
            }
            return(result);
        }