public async Task <int> Handle(CreateInfringementCommand request, CancellationToken cancellationToken) { try { var infringement = await _uow.InfringementRepository.FirstOrDefaultAsync(i => i.Id == request.Id); if (infringement != null) { throw new InfringementExistsException(infringement.Id); } infringement = new Infringement { Id = request.Id, Description = request.Description, Points = request.Id }; await _uow.InfringementRepository.AddAsync(infringement); await _uow.SaveChangesAsync(); return(infringement.Id); } catch { throw; } }
public void Add(Infringement infringement) { DisconnectEntities(infringement); db.Infringements.Add(infringement); db.SaveChanges(); infringement.BreachNo = infringement.Id.ToString(); Task.Factory.StartNew(() => db.SaveChanges()); }
public void Update(string id, Infringement infringement) { DisconnectEntities(infringement); db.Entry(infringement).State = EntityState.Modified; if (infringement.Customer != null) db.Entry(infringement.Customer).State = EntityState.Modified; if (infringement.Transaction != null) db.Entry(infringement.Transaction).State = EntityState.Modified; db.SaveChanges(); }
private void DisconnectEntities(Infringement infringement) { if (infringement.ParkingBuilding != null) { infringement.ParkingBuildingId = infringement.ParkingBuilding.Id; db.Entry(infringement.ParkingBuilding).State = EntityState.Unchanged; } if (infringement.Offense != null) { infringement.OffenseId = infringement.Offense.Id; db.Entry(infringement.Offense).State = EntityState.Unchanged; } //if (infringement.Transaction != null) //{ // infringement.TransactionId = infringement.Transaction.Reference; // db.Entry(infringement.Transaction).State = EntityState.Unchanged; //} }
public async Task <InfringementDto> InsertInfringementAsync(InfringementDto infringementDto) { if (infringementDto == null) { return(null); } var infringement = new Infringement() { UserId = infringementDto.UserId, CreatorId = infringementDto.CreatorId, Description = infringementDto.Description, CreatedAt = DateTime.Now }; await _context.Infringements.AddAsync(infringement); var checkInsert = await Complete(); return(checkInsert ? infringementDto : null); }
public async Task <Unit> Handle(Data request, CancellationToken cancellationToken) { Guid _Id = Guid.NewGuid(); var infringement = new Infringement { Id = _Id, Description = request.Description, Points_To_Discount = request.Points_To_Discount, Status = true }; _infringementRepository.Add(infringement); var value = await _infringementRepository.Commit(); if (value > 0) { return(Unit.Value); } throw new Exception("The record was not inserted"); }
public void Delete(Infringement Infringement) { db.Infringements.Remove(Infringement); db.SaveChanges(); }