public
override
ProductItem CreateProduct()
{
return
this
.CreateProduct(Guid.NewGuid());
}
public
override
ProductItem CreateProduct(Guid id)
{
var product =
new
ProductItem();
product.Id = id;
product.ApplicationName =
this
.ApplicationName;
product.Owner = SecurityManager.GetCurrentUserId();
var dateValue = DateTime.UtcNow;
product.DateCreated = dateValue;
product.PublicationDate = dateValue;
((IDataItem)product).Provider =
this
;
// products permissions inherit form the security root
var securityRoot =
this
.GetSecurityRoot();
if
(securityRoot !=
null
)
{
this
.providerDecorator.CreatePermissionInheritanceAssociation(securityRoot, product);
}
else
{
var msg = Res.Get<SecurityResources>().NoSecurityRoot;
msg =
string
.Format(msg,
typeof
(ProductItem).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(product);
}
return
product;
}
public
override
ProductItem GetProduct(Guid id)
{
if
(id == Guid.Empty)
{
throw
new
ArgumentException(
"Id cannot be Empty Guid"
);
}
// Always use this method. Do NOT change it to query. Catch the exception if the Id can be wrong.
var newsItem =
this
.GetContext().GetItemById<ProductItem>(id.ToString());
((IDataItem)newsItem).Provider =
this
;
return
newsItem;
}
public
override
IQueryable<ProductItem> GetProducts()
{
var appName =
this
.ApplicationName;
var query =
SitefinityQuery
.Get<ProductItem>(
this
, MethodBase.GetCurrentMethod())
.Where(b => b.ApplicationName == appName);
return
query;
}
public
override
void
DeleteProduct(ProductItem product)
{
var scope =
this
.GetContext();
this
.ClearContentLinks(product);
this
.providerDecorator.DeletePermissions(product);
this
.ClearLifecycle(product,
this
.GetProducts());
if
(scope !=
null
)
{
scope.Remove(product);
}
this
.DeleteItemComments(product.GetType(), product.Id);
}