コード例 #1
0
        public string Create(
            Entity entity,
            FormCollection collection,
            HttpFileCollectionBase files)
        {
            entity.Fill(collection, files);
            if (_validator.Validate(entity) == false)
            {
                _notificator.Error("Not valid");
                return(null);
            }
            var existingRecord = _source.GetRecord(entity, entity.Key.Select(x => x.Value.AsObject));

            if (existingRecord != null)
            {
                _notificator.Error(IlaroAdminResources.EntityAlreadyExist);
                return(null);
            }

            var propertiesWithUploadedFiles = _filesHandler.Upload(entity);

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

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

            return(id);
        }
コード例 #2
0
        public string Create(
            Entity entity,
            FormCollection collection,
            IFormFileCollection files)
        {
            var entityRecord = entity.CreateRecord(collection, files, x => x.OnCreateDefaultValue);

            if (_validator.Validate(entityRecord) == false)
            {
                _notificator.Error(IlaroAdminResources.RecordNotValid);
                return(null);
            }
            var existingRecord = _source.GetRecord(
                entity,
                entityRecord.Keys.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);
        }