public void Update(CategoryPermissionForRole item)
 {
     // Check there's not an object with same identifier already in context
     if (this._context.CategoryPermissionForRole.Local.Select(x => x.Id == item.Id).Any())
     {
         throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
     }
     this._context.Entry(item).State = EntityState.Modified;
 }
        /// <summary>
        /// Check the category permission for role actually exists
        /// </summary>
        /// <param name="categoryPermissionForRole"></param>
        /// <returns></returns>
        public CategoryPermissionForRole CheckExists(CategoryPermissionForRole categoryPermissionForRole)
        {
            if (categoryPermissionForRole.Permission != null &&
                    categoryPermissionForRole.Category != null &&
                        categoryPermissionForRole.Role != null)
            {

                return this._categoryPermissionForRoleService.GetByPermissionRoleCategoryId(categoryPermissionForRole.Permission.Id,
                                                          categoryPermissionForRole.Role.Id,
                                                          categoryPermissionForRole.Category.Id);
            }

            return null;
        }
 public void Delete(CategoryPermissionForRole categoryPermissionForRole)
 {
     this._context.CategoryPermissionForRole.Remove(categoryPermissionForRole);
 }
 public CategoryPermissionForRole Add(CategoryPermissionForRole categoryPermissionForRole)
 {
     return this._context.CategoryPermissionForRole.Add(categoryPermissionForRole);
 }
        /// <summary>
        /// Either updates a CPFR if exists or creates a new one
        /// </summary>
        /// <param name="categoryPermissionForRole"></param>
        public void UpdateOrCreateNew(CategoryPermissionForRole categoryPermissionForRole)
        {
            // Firstly see if this exists already
            var permission = CheckExists(categoryPermissionForRole);

            // if it exists then just update it
            if (permission != null)
            {
                permission.IsTicked = categoryPermissionForRole.IsTicked;
            }
            else
            {
                Add(categoryPermissionForRole);
            }
        }
 /// <summary>
 /// Saves/Updates CPFR
 /// </summary>
 /// <param name="categoryPermissionForRole"></param>
 public void Save(CategoryPermissionForRole categoryPermissionForRole)
 {
     this._categoryPermissionForRoleService.Update(categoryPermissionForRole);
 }
 /// <summary>
 /// Add new category permission for role
 /// </summary>
 /// <param name="categoryPermissionForRole"></param>
 public void Add(CategoryPermissionForRole categoryPermissionForRole)
 {
     this._categoryPermissionForRoleService.Add(categoryPermissionForRole);
 }