public HttpResponseMessage Create(HttpRequestMessage request, AppGroupViewModel appGroupViewModel)
        {
            if (ModelState.IsValid)
            {
                var newAppGroup = new AppGroup();
                newAppGroup.Name = appGroupViewModel.Name;
                try
                {
                    var appGroup = _appGroupService.Add(newAppGroup);

                    //save group
                    var listRoleGroup = new List <AppRoleGroup>();
                    foreach (var role  in appGroupViewModel.Roles)
                    {
                        listRoleGroup.Add(new AppRoleGroup()
                        {
                            GroupId = appGroup.Id,
                            RoleId  = role.Id
                        });
                    }
                    _appRoleService.AddRolesToGroup(listRoleGroup, appGroup.Id);
                    _appRoleService.Save();



                    return(request.CreateResponse(HttpStatusCode.OK, appGroupViewModel));
                }
                catch (NameDuplicatedException dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }