Beispiel #1
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);
            }

            entity.Fill(key, collection, files);
            if (_validator.Validate(entity) == false)
            {
                _notificator.Error("Not valid");
                return(false);
            }

            var propertiesWithUploadedFiles = _filesHandler.Upload(entity);

            _comparer.SkipNotChangedProperties(entity, existingRecord);

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

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

            return(result);
        }
Beispiel #2
0
        public bool Edit(
            Entity entity,
            string key,
            FormCollection collection,
            IFormFileCollection files,
            object concurrencyCheckValue = null)
        {
            try
            {
                var existingRecord = _source.GetRecord(entity, key);
                if (existingRecord == null)
                {
                    _notificator.Error(IlaroAdminResources.EntityNotExist);
                    return(false);
                }

                var entityRecord = entity.CreateRecord(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 = false;

                try
                {
                    result = _updater.Update(
                        entityRecord,
                        concurrencyCheckValue,
                        () => _changeDescriber.UpdateChanges(entityRecord, existingRecord));
                }
                catch (Exception ex)
                {
                    _log.Error(ex.Message);
                    _notificator.Error(ex.Message);
                }

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

                return(result);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                _notificator.Error(ex.Message);

                return(false);
            }
        }