public async Task <DepoEventDto> Update(DepoEventDto input) { if (input.Inspection != null && input.InspectionTxt != null) { throw new Exception("Инспекцию можно либо выбрать, либо задать текстом"); } var sql = @"update [DepoEvents] set [ParkingId]=@ParkingId,[InspectionId]=@InspectionId,[InspectionTxt]=@InspectionTxt,[TrainId]=@TrainId,[RouteId]=@RouteId,[InTime]=@InTime, [ParkingTime]=@ParkingTime,[RepairStopTime]=@RepairStopTime,[TestStartTime]=@TestStartTime,[TestStopTime]=@TestStopTime,[UserId]=@UserId where id=@Id"; await _db.Connection.ExecuteAsync(sql, new { ParkingId = input.Parking?.Id, InspectionId = input.Inspection?.Id, InspectionTxt = input.InspectionTxt, TrainId = input.Train?.Id, RouteId = input.Route?.Id, InTime = input.InTime, ParkingTime = input.ParkingTime, RepairStopTime = input.RepairStopTime, TestStartTime = input.TestStartTime, TestStopTime = input.TestStopTime, UserId = input.TesterUser?.Id, Id = input.Id }); return(await ById(input.Id)); }
public async Task <DepoEventDto> Create(DepoEventDto input) { if (input.Inspection != null && input.InspectionTxt != null) { throw new Exception("Инспекцию можно либо выбрать, либо задать текстом"); } var sql = @"insert into [DepoEvents] ([ParkingId],[InspectionId],[InspectionTxt],[TrainId],[RouteId],[InTime],[ParkingTime],[RepairStopTime],[TestStartTime],[TestStopTime],[UserId]) values ( @ParkingId,@InspectionId,@InspectionTxt,@TrainId,@RouteId,@InTime,@ParkingTime,@RepairStopTime,@TestStartTime,@TestStopTime,@UserId) SELECT SCOPE_IDENTITY()"; var id = await _db.Connection.QueryFirstOrDefaultAsync <int>(sql, new { ParkingId = input.Parking?.Id, InspectionId = input.Inspection?.Id, InspectionTxt = input.InspectionTxt, TrainId = input.Train?.Id, RouteId = input.Route?.Id, InTime = input.InTime, ParkingTime = input.ParkingTime, RepairStopTime = input.RepairStopTime, TestStartTime = input.TestStartTime, TestStopTime = input.TestStopTime, UserId = input.TesterUser?.Id }); return(await ById(id)); }
private static DepoEventDto BindToModel(IReadOnlyList <object> objects) { var ret = new DepoEventDto(); if (objects[0] is DepoEvent depoevent) { ret.Id = depoevent.Id; ret.InspectionTxt = depoevent.InspectionTxt; ret.InTime = depoevent.InTime; ret.ParkingTime = depoevent.ParkingTime; ret.RepairStopTime = depoevent.RepairStopTime; ret.TestStartTime = depoevent.TestStartTime; ret.TestStopTime = depoevent.TestStopTime; } if (objects[1] is Parking parking) { ret.Parking = new LiveSearchItemDto { Id = parking.Id, Name = parking.Name }; } if (objects[2] is Inspection inspection) { var brigade = objects[4] as Brigade; ret.Inspection = new LiveSearchItemDto { Id = inspection.Id, Name = GetInspectionString(inspection, brigade?.BrigadeType) }; } if (objects[5] is Train train) { ret.Train = new LiveSearchItemDto { Id = train.Id, Name = train.Name }; } if (objects[6] is Route route) { ret.Route = new LiveSearchItemDto { Id = route.Id, Name = route.Name }; } if (objects[7] is User user) { ret.TesterUser = new LiveSearchItemDto { Id = user.Id, Name = user.Name }; } return(ret); }