public PostResult<int> Post(RoleDetails model)
 {
     var result = GetDefault<PostResult<int>>();
     if (isExisted(model.Name, model.Id))
     {
         result.Message = "ROLE_NAME_HAS_EXIST";
         return result;
     }
     UserRole role = new UserRole()
     {
         RoleName = model.Name
     };
     if (model.Funs != null && model.Funs.Count() > 0)
     {
         model.Funs.ForEach(x =>
             role.UserPermissions.Add(new UserPermission()
             {
                 FunctionalityId = x.Id
             }));
     }
     DbEntities.UserRoles.Add(role);
     DbEntities.SaveChanges();
     result.Id = role.ID;
     result.IsCreated = true;
     return result;
 }
 public PutResult Put(RoleDetails role)
 {
     var result = GetDefault<PutResult>();
     var model = DbEntities.UserRoles.FirstOrDefault(x => x.ID == role.Id);
     if (model == null)
     {
         result.Message = "ROLE_NOT_EXIST";
         return result;
     }
     if (isExisted(role.Name, role.Id))
     {
         result.Message = "ROLE_NAME_HAS_EXIST";
         return result;
     }
     if (role.Funs != null && role.Funs.Count() > 0)
     {
         var list = model.UserPermissions.ToList();
         foreach (var item in list)
         {
             if (!role.Funs.Exists(x => x.Id == item.FunctionalityId))
             {
                 DbEntities.UserPermissions.Remove(item);
             }
         }
         foreach (var item in role.Funs)
         {
             if (!list.Exists(x => x.FunctionalityId == item.Id))
             {
                 model.UserPermissions.Add(new UserPermission() { FunctionalityId = item.Id, UserRoleId = role.Id });
             }
         }
     }
     model.RoleName = role.Name;
     DbEntities.SaveChanges();
     result.IsSaved = true;
     return result;
 }