Base solution for your next web application

Activities of "ddnils"

I am trying to create a nested route for one of my controllers.

I have tried this:

RouteConfig:

routes.MapHttpRoute(
                name: "InhabsApi",
                routeTemplate: "api/rooms/{id}/inhabitants/{inhabid}",
                defaults: new { inhabid = RouteParameter.Optional });

Controller looks like this:

[Abp.WebApi.Authorization.AbpApiAuthorize]
        public IHttpActionResult Get(long id)
        {
            return Ok(_roomService.GetAllInhabs(id));
        }

Unfortunatelly it does not work. I read Attribute Routing could help, but I am not sure if this works with Abp. Any help would be very appreciated :)

It did help to specify the controller in the route:

routes.MapHttpRoute(
                name: "InhabsApi",
                routeTemplate: "api/rooms/{id}/inhabitants/{inhabid}",
                defaults: new { controller = "Inhabitants", inhabid = RouteParameter.Optional });

Problem solved. But anyways, what do you think about Attribute Routing?

Question

I installed the nuGet package "ASP.NET WebAPI Route Debugger". It created a new Folder named Areas in .Web and inside Areas a Folder "RouteDebugger" with Components, Conrollers and so on. The documentation of Route Debugger states, that it should be available via /rd on my root page. Unfortunatelly it is not :(

<a class="postlink" href="http://blogs.msdn.com/b/webdev/archive/2013/04/04/debugging-asp-net-web-api-with-route-debugger.aspx">http://blogs.msdn.com/b/webdev/archive/ ... ugger.aspx</a>

Any ideas on how to solve this? I really need to debug my routes, for some unknown reason my put requests dont work.

You should probably ask this in a StackOverflow Angular department. Also I am not sure what your problem is... what do you want to do with the $scope.detail object?

best regards, Nils

Hi there, since GetAll() returns a Queryable, this indicates it filters on database. Since the SQL Query is not called yet and still in production. It will first be evaluated, when you call .ToList() or iterate manually over it. On the other hand: Thanks for evaluating this again :)

I can't get this to work with PUT

It works with GET and POST though....

not sure, what the problem is

It works! Finally got it working.

It was a rather stupid mistake, which i did oversee. I use Postman (chrome plugin) for testing and did provide a Content-Type = application/javascript instead of application/json

The answer is: Use Content-Type = application/json This works, thank you for your answer!

I have created a custom repository (i had to, my entity has a combined primary key (long,long)).

public class UserRelation
    {
        public virtual long UserId { get; set; }
        public virtual long FriendId { get; set; }
        [ForeignKey("UserId")]
        public virtual Users.User User { get; set; }
        [ForeignKey("FriendId")]
        public virtual Users.User Friend { get; set; }
        public DateTimeOffset RequestDate { get; set; }
        public DateTimeOffset? AcknowledgeDate { get; set; }
        public FriendRequestStatus FriendStatus { get; set; }
    }

OnModelCreating contains this code to instruct EntityFramework:

modelBuilder.Entity<Entities.UserRelation>().HasKey(f => new { f.UserId, f.FriendId });
            modelBuilder.Entity<Entities.UserRelation>()
              .HasRequired(f => f.User)
              .WithMany()
              .HasForeignKey(f => f.UserId);
            modelBuilder.Entity<Entities.UserRelation>()
                .HasRequired(f => f.Friend)
                .WithMany()
                .HasForeignKey(f => f.FriendId)
                .WillCascadeOnDelete(false);

So I created my custom repository in [].EntityFramework.Repositories Structure:

public class FriendsRepository: EntityFramework.Repositories.IFriendsRepository {}
interface IFriendsRepository : IRepository<Entities.UserRelation>
    {
        System.Threading.Tasks.Task<bool> ApproveFriendshipAsync(long UserId, long FriendId);
        System.Threading.Tasks.Task<Entities.UserRelation> CreateFriendshipAsync(long UserId, long FriendId);
        System.Linq.IQueryable<Entities.UserRelation> GetAllFriendsOfUserId(long UserId);
        System.Linq.IQueryable<Entities.UserRelation> GetAllRelationsOfUserId(long UserId);
        System.Threading.Tasks.Task<Entities.UserRelation> SetFriendshipStatusAsync(long UserId, long FriendId, Entities.FriendRequestStatus status);
    }

But now I wonder how I can inject it into my service structure, since the entityframework project is not referenced in [].Application?

Have I done something wrong? Or is something still missing? Any help is welcome :)

Hi, I am not sure about this, but have you tried [Abp.WebApi.Authorization.AbpApiAuthorize] ?

Have you checked embedded resources in Abp.Core?

Also check: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Localization">http://www.aspnetboilerplate.com/Pages/ ... calization</a>

Showing 1 to 10 of 28 entries