private JsonBase64Item ConvertFromDto(JsonBase64ItemDto itemDto) { if (itemDto == null) { return(null); } else { JsonBase64Item item = new JsonBase64Item() { Id = itemDto.Id, Data = itemDto.Data, Position = (itemDto.Position == EJsonBase64Position.Left ? "L" : "R") }; return(item); } }
public async Task <bool> Save(JsonBase64ItemDto entity) { string position = entity.Position == EJsonBase64Position.Left ? "L" : "R"; JsonBase64Item item = new JsonBase64Item() { Id = entity.Id, Data = entity.Data, Position = position }; try { if (await _repository.AddOrUpdate(item)) { _repository.Save(); } return(await Task.FromResult(true)); } catch (Exception ex) { return(await Task.FromResult(false)); } }
private JsonBase64Context GetContextWithData() { var options = new DbContextOptionsBuilder <JsonBase64Context>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new JsonBase64Context(options); var jsonBase64ItemLEFT = new JsonBase64Item { Id = "1", Position = "L", Data = "YXNkZmFzZGZhc2RmYXNkZmFzZGY=" }; var jsonBase64ItemRIGHT = new JsonBase64Item { Id = "1", Position = "R", Data = "YXNkZmFzZGZhc2RmYXNkZmFzZGY=" }; context.JsonBase64Items.Add(jsonBase64ItemLEFT); context.JsonBase64Items.Add(jsonBase64ItemRIGHT); context.SaveChanges(); return(context); }
public async Task <bool> AddOrUpdate(JsonBase64Item entity) { try { JsonBase64Item foundItem = await Select(entity.Id, entity.Position); if (foundItem == null) { _context.Add(entity); } else { foundItem.Data = entity.Data; } return(await Task.FromResult(true)); } catch (Exception ex) { return(await Task.FromResult(false)); } }