Exemple #1
0
        public void DeleteCigar(int cigarId)
        {
            _logger.LogInformation("Deleting cigar with ID {cigarId}", cigarId);
            Cigar entity = _dbContext.Cigar.Find(cigarId);

            _dbContext.Remove(entity);
        }
Exemple #2
0
        public Library.Models.Cigar GetCigarById(int id)
        {
            Cigar cigar = _dbContext.Cigar.Include(m => m.Manufacturer)
                          .AsNoTracking().First(m => m.Id == id);

            return(Mapper.Map(cigar));
        }
Exemple #3
0
        public void UpdateCigar(Library.Models.Cigar cigar)
        {
            _logger.LogInformation("Updating cigar with ID {cigarId}", cigar.Id);

            Cigar currentEntity = _dbContext.Cigar.Find(cigar.Id);
            Cigar newEntity     = Mapper.Map(cigar);

            _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity);
        }
Exemple #4
0
        public void AddCigar(Library.Models.Cigar cigar)
        {
            if (cigar.Id != 0)
            {
                _logger.LogWarning("Cigar to be added has an ID ({cigarId}) already: ignoring.", cigar.Id);
            }

            _logger.LogInformation($"Adding cigar");

            Cigar entity = Mapper.Map(cigar);

            entity.Id = 0;
            _dbContext.Add(entity);
        }
 public static Library.Models.Cigar Map(Entities.Cigar cigar) => new Library.Models.Cigar
 {
     Id        = cigar.Id,
     CigarName = cigar.Name,
 };