Exemplo n.º 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);
        }
        public void get_record_with_correct_key_value_return_record()
        {
            DB.Products.Insert(ProductName: "Product");
            var productId = DB.Products.Insert(ProductName: "Product2").ProductID;

            var record = _source.GetRecord(_entity, productId);

            Assert.NotNull(record);
            Assert.Equal("Product2", record["ProductName"]);
        }
Exemplo n.º 3
0
        public string Create(Entity entity)
        {
            var existingItem = _source.GetRecord(entity, entity.Key.Value.AsObject);

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

            var id = _creator.Create(entity);

            return(id);
        }
Exemplo n.º 4
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);
        }