Exemple #1
0
        private Guid AddInternal <TEntity>(CoreDTO dto, bool?isUpdating = null) where TEntity : class, IEntity
        {
            TEntity entity = null;

            if (isUpdating == false || dto.Id == Guid.Empty)
            {
                entity = _mapper.Map <TEntity>(dto);
                Repository.Add(entity);
            }
            else
            {
                var entityToUpdate = Repository.GetEntity <TEntity>(x => x.Id == dto.Id).FirstOrDefault();
                if (entityToUpdate == null)
                {
                    if (isUpdating == true)
                    {
                        return(Guid.Empty);
                    }
                    else
                    {
                        entity = _mapper.Map <TEntity>(dto);
                        Repository.Add(entity);
                    }
                }
                else
                {
                    Repository.Update(_mapper.Map(dto, entityToUpdate));
                    entity = entityToUpdate;
                }
            }

            return(entity == null ? Guid.Empty : entity.Id);
        }
        public static void AssertCanWriteDto(this UserInfo userInfo, string entityName, CoreDTO dto)
        {
            if (userInfo.Rights == null)
            {
                throw new NoRightsException();
            }

            userInfo.Rights.AssertCanWriteEntity(entityName, dto);
        }
Exemple #3
0
 public virtual Guid Add <TEntity>(CoreDTO dto, bool?isUpdating = null)
     where TEntity : class, IEntity
 {
     return(AddInternal <TEntity>(dto, isUpdating));
 }