/// <summary> /// Creates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <returns>T.</returns> protected T Create(T entity) { if (entity == null) { CreateErrors.NotValid("", nameof(entity)); } if (string.IsNullOrEmpty(entity?.Id.ToString()) || entity.Id.ToString() == Guid.Empty.ToString() || entity.Id.ToString() == "0") { CreateErrors.NotValid("", nameof(entity.Id)); } if (Repository.Get(entity.Id) != null) { CreateErrors.ItemAlreadyExists(entity.Id); } entity.ModifiedBy(ServiceBase.GetUserName()); entity.Validate(); entity.Activate(); T newEntity = Repository.Create(entity); _queueRepository.AddToQueue(newEntity.AddEntryToQueue <T, TId>("Create")); return(newEntity); }
/// <summary> /// Updates the specified entity. /// </summary> /// <param name="entity">The entity.</param> protected void Update(T entity) { if (entity == null) { CreateErrors.NotValid("", nameof(entity)); } if (string.IsNullOrEmpty(entity?.Id.ToString()) || entity.Id.ToString() == Guid.Empty.ToString() || entity.Id.ToString() == "0") { CreateErrors.NotValid("", nameof(entity.Id)); } T original = Repository.Get(entity.Id); entity.ModifiedBy(ServiceBase.GetUserName()); entity.Validate(); Repository.Update(entity); _archiverRepository.Archive(original.ArchiveEntity <T, TId>(entity)); _queueRepository.AddToQueue(entity.AddEntryToQueue <T, TId>("Update")); }
/// <summary> /// Gets the specified entity identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns>Store.</returns> /// <exception cref="NotValidException"></exception> /// <exception cref="Core.Common.Exceptions.NotValidException"></exception> /// <exception cref="ResourceNotFoundException"></exception> /// <exception cref="Core.Common.Exceptions.ResourceNotFoundException"></exception> protected T Get(TId id) { if (id == null) { CreateErrors.NotValid("", nameof(id)); } if (string.IsNullOrEmpty(id.ToString()) || id.ToString() == Guid.Empty.ToString() || id.ToString() == "0") { throw new NotValidException(id.ToString()); } T entity = ReadOnlyRepository.Get(id); if (entity == null) { CreateErrors.NotFound(id); } return(entity); }
/// <summary> /// Deletes the specified identifier. /// </summary> /// <param name="id">The identifier.</param> protected void Delete(TId id) { if (id == null) { CreateErrors.NotValid("", nameof(id)); } if (string.IsNullOrEmpty(id.ToString()) || id.ToString() == Guid.Empty.ToString() || id.ToString() == "0") { CreateErrors.NotValid(id.ToString(), nameof(id)); } T entity = Repository.Get(id); if (entity != null) { T original = entity.Clone(); entity.ModifiedBy(ServiceBase.GetUserName()); entity.DeActivate(); Repository.Update(entity); _archiverRepository.Archive(original.ArchiveEntity <T, TId>(entity)); _queueRepository.AddToQueue(entity.AddEntryToQueue <T, TId>("Delete")); } }