Beispiel #1
0
        public IActionResult Create([FromBody] CreateAttributeViewModel model)
        {
            try
            {
                var result = attributeRepository.Create(new
                {
                    model.Name,
                    model.Description,
                    model.SourceConnectionId,
                    model.DestinationConnectionId,
                    model.EntityId,
                    model.SourceProcessorId,
                    model.DestinationProcessorId,
                    State = 0
                });

                if (model.Options != null && model.Options.Count() > 0)
                {
                    attributeRepository.LinkOptions(result, model.Options);
                }

                transaction.Commit();
                return(Ok(result));
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
        }
        public IActionResult Update(string id, [FromBody] CreateAttributeViewModel model)
        {
            AttributeRepository attributeRepository = null;

            try
            {
                attributeRepository = ResolverFactory.Resolve <AttributeRepository>();
                var attributeModel = attributeRepository.GetById(id);
                var state          = attributeModel.State;
                if (model.Enabled)
                {
                    state = (state | EntityState.Disabled) ^ EntityState.Disabled;
                }
                else
                {
                    state = state | EntityState.Disabled;
                }
                var result = attributeRepository.Update(id, new
                {
                    model.Name,
                    model.Description,
                    model.SourceConnectionId,
                    model.DestinationConnectionId,
                    model.EntityId,
                    model.SourceProcessorId,
                    model.DestinationProcessorId,
                    State = state
                });

                if (model.Options != null && model.Options.Count() > 0)
                {
                    attributeRepository.LinkOptions(id, model.Options);
                }

                transaction.Commit();
                return(Ok(result));
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                attributeRepository?.Dispose();
            }
        }
        public IActionResult UpdateOptions(string id, [FromBody] IEnumerable <OptionItem> options)
        {
            AttributeRepository attributeRepository = null;

            try
            {
                attributeRepository = ResolverFactory.Resolve <AttributeRepository>();
                if (options != null && options.Count() > 0)
                {
                    attributeRepository.LinkOptions(id, options);
                }
                transaction.Commit();
                return(Ok(id));
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                attributeRepository?.Dispose();
            }
        }