Exemplo n.º 1
0
        public Result <int> Save(CodeMapperItem entity)
        {
            switch (entity.EntityState)
            {
            case ItemState.Added:
                return(_commandRepository.Add(entity.MapTo <CodeMappers>()).MapResultTo <int, object>());

            case ItemState.Modified:
                if (!entity.IsDefault)
                {
                    return(_commandRepository.InlineUpdate(entity, entity.Id));
                }
                return(ResetDefault().Bind <int>(x => _commandRepository.InlineUpdate(entity, entity.Id)));

            case ItemState.Delete:
                return(_commandRepository.Delete(entity.Id));

            case ItemState.Unchanged:
                return(Result <int> .Fail <int>("Unchanged Object. Nothing to save"));

            default:
                return(Result <int> .Fail <int>("Entity state unknown"));
            }
        }
Exemplo n.º 2
0
 public Result <int> Save(CodeMapperItem entity) => _command.Save(entity);
Exemplo n.º 3
0
 public Result <int> Put(int id, [FromBody] CodeMapperItem entity)
 {
     entity.EntityState = ItemState.Modified;
     return(_services.Save(entity));
 }
Exemplo n.º 4
0
 public Result <int> Post([FromBody] CodeMapperItem entity)
 {
     entity.EntityState = ItemState.Added;
     return(_services.Save(entity));
 }