Ejemplo n.º 1
0
        //public async Task<List<Navigation>> FindByRolesAsync(string[] roles)
        //{
        //    var navigationList = new List<Navigation>();
        //    foreach(var role in roles)
        //    {
        //        navigationList.AddRange(await FindByRoleAsync(role));
        //    }
        //    return navigationList;
        //}

        //public async Task<List<string>> GetActionKeyByRoleAsync(string roleName)
        //{
        //    var roleDto = await _roleManager.FindByNameAsync(roleName);
        //    var roleNavigation = await _roleNavigationRepository.FindByAsync(x => x.RoleId.Equals(roleDto.Id));
        //    var actionKey = new List<string>();
        //    foreach (var item in roleNavigation)
        //    {
        //        var nav = await _navigationRepository.GetSingleAsync(item.NavigationId);
        //        actionKey.Add(String.Format("{0}-{1}",nav.ControllerName, nav.ActionName));
        //    }
        //    return actionKey;
        //}


        public async Task <ApplicationIdentityResult> AddAsync(NavigationMenu navigation)
        {
            var NavigationMenuEntity = (await _navigationRepository.FindByAsync(x => x.Name == navigation.Name)).FirstOrDefault();
            var alreadyExist         = NavigationMenuEntity != null;

            if (alreadyExist)
            {
                return(new ApplicationIdentityResult(new[] { "Navigation with this name is already Exist" }, false));
            }

            var dto = navigation.ToNavigationMenuEntity();

            dto.NavigationType = await _navigationTypeRepository.GetSingleAsync(navigation.NavigationTypeId);

            dto.InsertedOnUtc = DateTime.UtcNow;

            _navigationRepository.Insert(dto);
            await _unitOfWork.SaveChangesAsync();

            navigation = dto.ToNavigationMenu();
            return(new ApplicationIdentityResult(new[] { "" }, true));
        }