Ejemplo n.º 1
0
        public EntityRecord GetEntityRecord(Entity entity, params string[] key)
        {
            var keys = new object[key.Length];
            for (int i = 0; i < key.Length; i++)
            {
                keys[i] = new PropertyValue(entity.Key[i]).ToObject(key[i]);
            }
            var item = GetRecord(entity, keys);
            if (item == null)
            {
                _notificator.Error(IlaroAdminResources.EntityNotExist);
                return null;
            }

            var entityRecord = new EntityRecord(entity);
            entityRecord.Fill(item);

            return entityRecord;
        }
Ejemplo n.º 2
0
        public string Create(
            Entity entity,
            FormCollection collection,
            HttpFileCollectionBase files)
        {
            var entityRecord = new EntityRecord(entity);
            entityRecord.Fill(collection, files, x => x.OnCreateDefaultValue);
            if (_validator.Validate(entityRecord) == false)
            {
                _notificator.Error(IlaroAdminResources.RecordNotValid);
                return null;
            }
            var existingRecord = _source.GetRecord(
                entity,
                entityRecord.Key.Select(value => value.AsObject).ToArray());
            if (existingRecord != null)
            {
                _notificator.Error(IlaroAdminResources.EntityAlreadyExist);
                return null;
            }

            var propertiesWithUploadedFiles = _filesHandler.Upload(
                entityRecord,
                x => x.OnCreateDefaultValue);

            var id = _creator.Create(
                entityRecord,
                () => _changeDescriber.CreateChanges(entityRecord));

            if (id.IsNullOrWhiteSpace() == false)
                _filesHandler.ProcessUploaded(propertiesWithUploadedFiles);
            else
                _filesHandler.DeleteUploaded(propertiesWithUploadedFiles);

            return id;
        }
Ejemplo n.º 3
0
        private static EntityRecord create_filter_record(
            Entity entity,
            NameValueCollection request)
        {
            var filterRecord = new EntityRecord(entity);
            if (request != null)
                filterRecord.Fill(request);

            return filterRecord;
        }
Ejemplo n.º 4
0
        public bool Delete(Entity entity, string key, IEnumerable<PropertyDeleteOption> options)
        {
            var existingRecord = _source.GetRecord(entity, key);
            if (existingRecord == null)
            {
                _notificator.Error(IlaroAdminResources.EntityNotExist);
                return false;
            }
            var entityRecord = new EntityRecord(entity);
            entityRecord.Fill(existingRecord);

            options = options ?? new List<PropertyDeleteOption>();
            var deleteOptions = options.ToDictionary(x => x.HierarchyName);

            var result = _deleter.Delete(
                entityRecord,
                deleteOptions,
                () => _changeDescriber.DeleteChanges(entityRecord, existingRecord));

            if (result)
            {
                var propertiesWithFilesToDelete = entityRecord.Values
                    .Where(value => value.Property.TypeInfo.IsFile && value.Property.TypeInfo.IsFileStoredInDb == false);
                _filesHandler.Delete(propertiesWithFilesToDelete);
            }

            return result;
        }
Ejemplo n.º 5
0
        public bool Edit(
            Entity entity,
            string key,
            FormCollection collection,
            HttpFileCollectionBase files)
        {
            var existingRecord = _source.GetRecord(entity, key);
            if (existingRecord == null)
            {
                _notificator.Error(IlaroAdminResources.EntityNotExist);
                return false;
            }

            var entityRecord = new EntityRecord(entity);
            entityRecord.Fill(key, collection, files, x => x.OnUpdateDefaultValue);
            if (_validator.Validate(entityRecord) == false)
            {
                _notificator.Error(IlaroAdminResources.RecordNotValid);
                return false;
            }

            var propertiesWithUploadedFiles = _filesHandler.Upload(
                entityRecord,
                x => x.OnUpdateDefaultValue);

            _comparer.SkipNotChangedProperties(entityRecord, existingRecord);

            var result = _updater.Update(
                entityRecord,
                () => _changeDescriber.UpdateChanges(entityRecord, existingRecord));

            if (result)
                _filesHandler.ProcessUploaded(propertiesWithUploadedFiles, existingRecord);
            else
                _filesHandler.DeleteUploaded(propertiesWithUploadedFiles);

            return result;
        }