/// <summary> /// Converts the domain model into an entity. /// </summary> /// <returns>The entity.</returns> /// <param name="biome">Biome.</param> internal static BiomeEntity ToEntity(this Biome biome) { BiomeEntity biomeEntity = new BiomeEntity { Id = biome.Id, Name = biome.Name, Description = biome.Description, ColourHexadecimal = ColorTranslator.ToHtml(biome.Colour) }; return(biomeEntity); }
/// <summary> /// Converts the entity into a domain model. /// </summary> /// <returns>The domain model.</returns> /// <param name="biomeEntity">Biome entity.</param> internal static Biome ToDomainModel(this BiomeEntity biomeEntity) { Biome biome = new Biome { Id = biomeEntity.Id, Name = biomeEntity.Name, Description = biomeEntity.Description, Colour = ColorTranslator.FromHtml(biomeEntity.ColourHexadecimal) }; return(biome); }
/// <summary> /// Get the biome with the specified identifier. /// </summary> /// <returns>The biome.</returns> /// <param name="id">Identifier.</param> public BiomeEntity Get(string id) { List <BiomeEntity> biomeEntities = xmlDatabase.LoadEntities().ToList(); BiomeEntity biomeEntity = biomeEntities.FirstOrDefault(x => x.Id == id); if (biomeEntity == null) { throw new EntityNotFoundException(id, nameof(BiomeEntity).Replace("Entity", "")); } return(biomeEntity); }
/// <summary> /// Adds the specified biome. /// </summary> /// <param name="biomeEntity">Biome.</param> public void Add(BiomeEntity biomeEntity) { List <BiomeEntity> biomeEntities = xmlDatabase.LoadEntities().ToList(); biomeEntities.Add(biomeEntity); try { xmlDatabase.SaveEntities(biomeEntities); } catch { throw new DuplicateEntityException(biomeEntity.Id, nameof(BiomeEntity).Replace("Entity", "")); } }
/// <summary> /// Updates the specified biome. /// </summary> /// <param name="biomeEntity">Biome.</param> public void Update(BiomeEntity biomeEntity) { List <BiomeEntity> biomeEntities = xmlDatabase.LoadEntities().ToList(); BiomeEntity biomeEntityToUpdate = biomeEntities.FirstOrDefault(x => x.Id == biomeEntity.Id); if (biomeEntityToUpdate == null) { throw new EntityNotFoundException(biomeEntity.Id, nameof(BorderEntity).Replace("Entity", "")); } biomeEntityToUpdate.Name = biomeEntity.Name; biomeEntityToUpdate.Description = biomeEntity.Description; biomeEntityToUpdate.ColourHexadecimal = biomeEntity.ColourHexadecimal; xmlDatabase.SaveEntities(biomeEntities); }