/// <summary> /// Create an agent item with specific primary key /// </summary> /// <param name="id">Primary key</param> /// <returns>Newly created agent item in transaction</returns> public override AgentItem CreateAgent(Guid id) { var agent = new AgentItem(); agent.Id = id; agent.ApplicationName = this.ApplicationName; agent.Owner = SecurityManager.GetCurrentUserId(); var dateValue = DateTime.UtcNow; agent.DateCreated = dateValue; agent.PublicationDate = dateValue; ((IDataItem)agent).Provider = this; // agent permissions inherit form the security root var securityRoot = this.GetSecurityRoot(); if (securityRoot != null) { this.providerDecorator.CreatePermissionInheritanceAssociation(securityRoot, agent); } else { var msg = Res.Get<SecurityResources>().NoSecurityRoot; msg = string.Format(msg, typeof(AgentItem).AssemblyQualifiedName); throw new InvalidOperationException(msg); } // items with empty guid are used in the UI to get a "blank" data item // -> i.e. to fill a data item with default values // if this is the case, we leave the item out of the transaction if (id != Guid.Empty) { this.GetContext().Add(agent); } return agent; }
/// <summary> /// Initializes a new instance of the <see cref="AgentItemViewModel"/> class. /// </summary> /// <param name="contentItem">The content item.</param> /// <param name="provider">The provider.</param> public AgentItemViewModel(AgentItem contentItem, ContentDataProviderBase provider) : base(contentItem, provider) { this.agentEmail = contentItem.Email; this.agentPhoneNumber = contentItem.PhoneNumber; this.agentAddress = contentItem.Address; this.agentPostalCode = contentItem.PostalCode; }
/// <summary> /// Delete an agent /// </summary> /// <param name="product">Agent to delete</param> public override void DeleteAgent(AgentItem agent) { var scope = this.GetContext(); //remove the item from the parent list of inheritors //var securityRoot = this.GetSecurityRoot(); //if (securityRoot != null) //{ // List<PermissionsInheritanceMap> parentInheritors = securityRoot.PermissionChildren.Where(c => c.ChildObjectId == agent.Id).ToList(); // for (int inheritor = 0; inheritor < parentInheritors.Count(); inheritor++) // { // securityRoot.PermissionChildren.Remove(parentInheritors[inheritor]); // } //} //remove the relevant permissions this.providerDecorator.DeletePermissions(agent); this.ClearLifecycle(agent, this.GetAgents()); if (scope != null) { scope.Remove(agent); } }