public void UpdatePermission(AjaxEditPermissionViewModel ajaxEditPermissionViewModel)
        {
            using (var unitOfWork = _unitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    var mappedItem = new CategoryPermission
                    {
                        CategoryId = ajaxEditPermissionViewModel.Category,
                        MemberGroupId = ajaxEditPermissionViewModel.MemberGroup,
                        Permission = ServiceFactory.PermissionService.Get(ajaxEditPermissionViewModel.Permission),
                        IsTicked = ajaxEditPermissionViewModel.HasPermission
                    };
                    ServiceFactory.CategoryPermissionService.UpdateOrCreateNew(mappedItem);

                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    unitOfWork.Rollback();
                    AppHelpers.LogError("Error updating permissions on category", ex);
                    throw;
                }
            }
        }
        /// <summary>
        /// Check the category permission for role actually exists
        /// </summary>
        /// <param name="categoryPermission"></param>
        /// <returns></returns>
        public CategoryPermission CheckExists(CategoryPermission categoryPermission)
        {
            if (categoryPermission.Permission != null)
            {

                return GetByPermissionRoleCategoryId(categoryPermission.Permission.Id,
                                                          categoryPermission.MemberGroupId,
                                                          categoryPermission.CategoryId);
            }

            return null;
        }
        /// <summary>
        /// Either updates a CPFR if exists or creates a new one
        /// </summary>
        /// <param name="categoryPermission"></param>
        public void UpdateOrCreateNew(CategoryPermission categoryPermission)
        {
            // Firstly see if this exists already
            var permission = CheckExists(categoryPermission);

            // if it exists then just update it
            if (permission != null)
            {
                permission.IsTicked = categoryPermission.IsTicked;
            }
            else
            {
                Add(categoryPermission);
            }
        }
 public void Delete(CategoryPermission categoryPermission)
 {
     ContextPerRequest.Db.CategoryPermission.Remove(categoryPermission);
 }
 public CategoryPermission Add(CategoryPermission categoryPermission)
 {
     return ContextPerRequest.Db.CategoryPermission.Add(categoryPermission);
 }