示例#1
0
        /// <summary>
        /// Creates a new element.
        /// </summary>
        /// <param name="settings">New element settings.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Newly allocated element identifier.</returns>
        public long Create(IElementSettings settings, IUnitOfWork unitOfWork = null)
        {
            try
            {
                IAdvancedElementService customElementService   = (IAdvancedElementService)_elementFactory.GetElementService(settings.ElementTypeId);
                ICustomElementValidator customElementValidator = _elementFactory.GetElementValidator(settings.ElementTypeId);
                IUnitOfWork             localUnitOfWork        = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

                try
                {
                    if (customElementValidator != null)
                    {
                        customElementValidator.ValidateCreate(settings, unitOfWork ?? localUnitOfWork);
                    }
                    settings.ElementId = _elementRepository.Create(settings, unitOfWork ?? localUnitOfWork);
                    if (customElementService != null)
                    {
                        customElementService.Create(settings, unitOfWork ?? localUnitOfWork);
                    }
                    if (localUnitOfWork != null)
                    {
                        localUnitOfWork.Commit();
                    }
                    return(settings.ElementId);
                }
                catch
                {
                    if (localUnitOfWork != null)
                    {
                        localUnitOfWork.Rollback();
                    }
                    throw;
                }
                finally
                {
                    if (localUnitOfWork != null)
                    {
                        localUnitOfWork.Dispose();
                    }
                }
            }
            catch (ValidationErrorException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
        }
示例#2
0
 /// <summary>
 /// Deletes an element.
 /// </summary>
 /// <param name="tenantId">The tenant that element to delete belongs to.</param>
 /// <param name="elementTypeId">Identifies the type of element to delete.</param>
 /// <param name="elementId">Identifies the element to delete.</param>
 /// <param name="unitOfWork">Unit of work.</param>
 public void Delete(long tenantId, Guid elementTypeId, long elementId, IUnitOfWork unitOfWork = null)
 {
     try
     {
         IAdvancedElementService customElementService   = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId);
         ICustomElementValidator customElementValidator = _elementFactory.GetElementValidator(elementTypeId);
         IUnitOfWork             localUnitOfWork        = (unitOfWork == null && customElementService != null) ? _unitOfWorkFactory.CreateUnitOfWork() : null;
         try
         {
             if (customElementValidator != null)
             {
                 customElementValidator.ValidateDelete(tenantId, elementTypeId, elementId, unitOfWork ?? localUnitOfWork);
             }
             if (customElementService != null)
             {
                 customElementService.Delete(tenantId, elementId, unitOfWork ?? localUnitOfWork);
             }
             _elementRepository.Delete(tenantId, elementId, unitOfWork ?? localUnitOfWork);
             if (localUnitOfWork != null)
             {
                 localUnitOfWork.Commit();
             }
         }
         catch
         {
             if (localUnitOfWork != null)
             {
                 localUnitOfWork.Rollback();
             }
             throw;
         }
         finally
         {
             if (localUnitOfWork != null)
             {
                 localUnitOfWork.Dispose();
             }
         }
     }
     catch (ValidationErrorException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
     }
 }
示例#3
0
 /// <summary>
 /// Updates an element's details.
 /// </summary>
 /// <param name="settings">Updated element details.</param>
 /// <param name="unitOfWork">Unit of work.</param>
 public void Update(IElementSettings settings, IUnitOfWork unitOfWork = null)
 {
     try
     {
         IAdvancedElementService customElementService   = (IAdvancedElementService)_elementFactory.GetElementService(settings.ElementTypeId);
         ICustomElementValidator customElementValidator = _elementFactory.GetElementValidator(settings.ElementTypeId);
         if (customElementValidator != null)
         {
             customElementValidator.ValidateUpdate(settings, unitOfWork);
         }
         if (customElementService != null)
         {
             customElementService.Update(settings, unitOfWork);
         }
     }
     catch (ValidationErrorException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
     }
 }