Пример #1
0
        public IActionResult CreateEntityType([FromRoute] string agentId, [FromBody] VmEntityType model)
        {
            if (model == null)
            {
                return(BadRequest("entity is empty"));
            }

            model.AgentId = agentId;
            model.Id      = Guid.NewGuid().ToString();

            dc.DbTran(() => {
                var entity = new EntityType
                {
                    Name        = model.Name,
                    AgentId     = model.AgentId,
                    IsEnum      = model.IsEnum,
                    Description = model.Description,
                    Entries     = model.Entries.Select(x => new EntityEntry
                    {
                        Value    = x.Value,
                        Synonyms = x.Synonyms.Select(synonym => new EntrySynonym
                        {
                            Synonym = synonym
                        }).ToList()
                    }).ToList()
                };

                dc.Table <EntityType>().Add(entity);
            });

            return(Ok(model.Id));
        }
Пример #2
0
        public String UpdateEntityType([FromRoute] string entityTypeId, [FromBody] VmEntityType model)
        {
            dc.DbTran(() => {
                // remove
                var entityType = dc.Table <EntityType>().Find(entityTypeId);
                dc.Table <EntityType>().Remove(entityType);
                dc.SaveChanges();

                // add back
                entityType             = model.ToEntityType(entityType);
                entityType.UpdatedTime = DateTime.UtcNow;

                dc.Table <EntityType>().Add(entityType);
            });

            return(model.Id);
        }