public void Save(BeerDTO beerDTO)
        {
            //_context.Database.BeginTransaction();

            if (beerDTO.Id.HasValue)
            {
                var beerModel = _beerRepository.GetById(beerDTO.Id.Value);
                if (beerModel == null)
                {
                    //_context.Database.RollbackTransaction();
                    throw new NotFoundException("L'identifiant de la bière n'est pas valide!");
                }

                beerModel.Name = beerDTO.Name;
                beerModel.Type = beerDTO.Type;

                _beerRepository.Edit(beerModel);
            }
            else
            {
                var beerModel = new Beer()
                {
                    Id           = null,
                    CreationDate = DateTime.Now,
                    Name         = beerDTO.Name,
                    Type         = beerDTO.Type
                };

                _beerRepository.Create(beerModel);
            }

            //_context.Database.CommitTransaction();
        }
Exemple #2
0
 public Task <Beer> Create(Beer beer)
 {
     beer.SubmittedByUser = _currentUserResolver.Get().Id;
     return(_repo.Create(beer));
 }
Exemple #3
0
 //<inheritdoc />
 public int Create(Beer beer)
 {
     return(_repository.Create(beer));
 }