Exemplo n.º 1
0
 public GetMenuResponse GetMenuByUrl(GetMenuRequestByUrl request)
 {
     try
     {
         var response = new GetMenuResponse();
         var menu = DataContext.Menus.AsNoTracking().Include(x => x.RoleGroups).FirstOrDefault(x => x.RoleGroups.Select(y => y.Id).Contains(request.RoleId) && x.Url.Contains(request.Url));
         if (menu != null)
         {
             response = menu.MapTo<GetMenuResponse>();
             response.IsSuccess = true;
         }
         else
         {
             response.IsSuccess = false;
             response.Message = "No Menu Found";
         }
         return response;
     }
     catch (System.InvalidOperationException x)
     {
         return new GetMenuResponse
         {
             IsSuccess = false,
             Message = x.Message
         };
     }
 }
Exemplo n.º 2
0
        public GetMenuResponse GetMenuByUrl(GetMenuRequestByUrl request)
        {
            try
            {
                //var role = DataContext.RoleGroups.First(x => x.Id == request.RoleId);
                //var menu = DataContext.Menus.Include(x => x.RoleGroups).Where(x=>x.RoleGroups == role).First(x => x.Url == request.Url);
                var url = request.Url != null ? request.Url.Split('/') : null;
                string authorized = "/";
                if (url[1].Length > 0)
                {
                    authorized = string.Format("/{0}/", url[1]);
                    //authorized += url[1];
                }
                var menu = DataContext.Menus.Include(x => x.RoleGroups).First(x => x.RoleGroups.Select(y => y.Id).Contains(request.RoleId) && x.Url.Contains(authorized));

                var response = menu.MapTo<GetMenuResponse>();
                response.IsSuccess = true;
                return response;
            }
            catch (System.InvalidOperationException x)
            {
                return new GetMenuResponse
                {
                    IsSuccess = false,
                    Message = x.Message
                };
            }
        }