public static async Task <HttpResponseMessage> UpdateAsync(this Resources.Role contact,
                                                                   HttpRequestMessage request, UrlHelper url)
        {
            var context = request.GetSessionServerContext();

            return(await context.Roles.UpdateAsync(contact.Id.UUID,
                                                   contact.Actor.ToGuid(), contact.Name,
                                                   () => request.CreateResponse(HttpStatusCode.NoContent),
                                                   (why) => request.CreateResponse(HttpStatusCode.Conflict).AddReason(why),
                                                   () => request.CreateResponse(HttpStatusCode.NotFound)));
        }
        private static async Task <HttpResponseMessage> QueryById(Guid roleId, HttpRequestMessage request, UrlHelper url)
        {
            var context = request.GetSessionServerContext();

            return(await context.Roles.GetByIdAsync(roleId,
                                                    (role) =>
            {
                var roleResource = new Resources.Role()
                {
                    Id = url.GetWebId <Controllers.RoleController>(role.id),
                    Actor = Library.configurationManager.GetActorLink(role.actorId, url),
                    Name = role.name,
                };
                return request.CreateResponse(HttpStatusCode.OK, roleResource);
            },
                                                    () => request.CreateResponse(HttpStatusCode.NotFound)));
        }
        public static async Task <HttpResponseMessage> CreateAsync(this Resources.Role role, HttpRequestMessage request, UrlHelper url)
        {
            var roleId = role.Id.ToGuid();

            if (!roleId.HasValue)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest).AddReason("Id must have value"));
            }

            var actorId = role.Actor.ToGuid();

            if (!actorId.HasValue)
            {
                return(request.CreateResponse(HttpStatusCode.BadRequest).AddReason("Actor must have value"));
            }

            var context = request.GetSessionServerContext();

            return(await context.Roles.CreateAsync(roleId.Value, actorId.Value, role.Name,
                                                   () => request.CreateResponse(HttpStatusCode.Created),
                                                   () => request.CreateResponse(HttpStatusCode.Conflict).AddReason("Contact already exists"),
                                                   () => request.CreateResponse(HttpStatusCode.Conflict).AddReason("Actor does not exists")));
        }