예제 #1
0
        public async Task <int> UpdateTransportlidzeklisAsync(Transportlidzeklis transportlidzeklis)
        {
            // numura maiņas gadījumā - pārbaudam vai šāds numurs jau eksistē
            var exist = await _context.Transportlidzekli.AsNoTracking()
                        .Where(t => t.Id != transportlidzeklis.Id && t.Numurs == transportlidzeklis.Numurs)
                        .CountAsync();

            if (exist > 0)
            {
                throw new BadRequestException("Transportlīdzeklis ar šādu reģistrācijas numuru jau eksistē");
            }

            var vehicle = await _context.Transportlidzekli.Where(t => t.Id == transportlidzeklis.Id).FirstAsync();

            vehicle.Numurs    = transportlidzeklis.Numurs;
            vehicle.Marka     = transportlidzeklis.Marka;
            vehicle.Modelis   = transportlidzeklis.Modelis;
            vehicle.Krasa     = transportlidzeklis.Krasa;
            vehicle.Gads      = transportlidzeklis.Gads;
            vehicle.Vin       = transportlidzeklis.Vin;
            vehicle.Tips      = transportlidzeklis.Tips;
            vehicle.Tilpums   = transportlidzeklis.Tilpums;
            vehicle.Variants  = transportlidzeklis.Variants;
            vehicle.Versija   = transportlidzeklis.Versija;
            vehicle.Degviela  = transportlidzeklis.Degviela;
            vehicle.Jauda     = transportlidzeklis.Jauda;
            vehicle.PilnaMasa = transportlidzeklis.PilnaMasa;
            vehicle.Pasmasa   = transportlidzeklis.Pasmasa;
            vehicle.Piezimes  = transportlidzeklis.Piezimes;

            return(await _context.SaveChangesAsync());
        }
        public async Task <IActionResult> UpdateVehicle([FromBody] Transportlidzeklis transportlidzeklis)
        {
            var result = await _repository.UpdateTransportlidzeklisAsync(transportlidzeklis);

            if (result > 0)
            {
                return(StatusCode(200, new { message = "Transportlīdzekļa dati atjaunināti" }));
            }
            return(StatusCode(200, new { message = "Nav izmaiņu ko saglabāt" }));
        }
예제 #3
0
        public async Task <int> InsertTransportlidzeklisAsync(Transportlidzeklis transportlidzeklis)
        {
            // pārbaudam vai šāds numurs jau eksistē
            var exist = await _context.Transportlidzekli.AsNoTracking()
                        .Where(t => t.Numurs == transportlidzeklis.Numurs)
                        .CountAsync();

            if (exist > 0)
            {
                throw new BadRequestException("Transportlīdzeklis ar šādu reģistrācijas numuru jau eksistē");
            }

            _memoryCache.Remove("TODAY-STATUS");

            await _context.Transportlidzekli.AddAsync(transportlidzeklis);

            await _context.SaveChangesAsync();

            return(transportlidzeklis.Id);
        }
예제 #4
0
 static void Parvietot(Transportlidzeklis tr)
 {
     tr.Parvietoties();
 }
        public async Task <IActionResult> InsertVehicle([FromBody] Transportlidzeklis transportlidzeklis)
        {
            var result = await _repository.InsertTransportlidzeklisAsync(transportlidzeklis);

            return(StatusCode(201, new { id = result, message = "Izveidots jauns transportlīdzeklis" }));
        }