示例#1
0
        public async Task <dynamic> postMaintenanceFlag([FromBody] MaintenanceDTO request)
        {
            var existingData = db.ServerFlags.Where(acs => acs.ServerFlag == "maintenance_mode").FirstOrDefault();

            if (existingData != null)
            {
                existingData.Value  = request.IsActive.ToString();
                existingData.FromDt = request.FromDt;
                existingData.ToDt   = request.ToDt;
                db.ServerFlags.Attach(existingData);
                db.Entry(existingData).State = EntityState.Modified;
            }
            else
            {
                var flag = new ServerFlags()
                {
                    ServerFlag = "maintenance_mode",
                    FromDt     = request.FromDt,
                    ToDt       = request.ToDt,
                    Value      = request.IsActive.ToString()
                };
                db.ServerFlags.Add(flag);
            }
            db.SaveChanges();

            return(Ok("Maintenance Flag Added"));
        }
示例#2
0
        public MaintenanceDTO Read(int maintenanceID)
        {
            using var connection = Connection.GetConnection();
            {
                connection.OpenAsync();

                using var command   = connection.CreateCommand();
                command.CommandText = "SELECT * FROM `Maintenance` WHERE MaintenanceID = @maintenanceID";
                command.Parameters.AddWithValue("@maintenanceID", maintenanceID);

                var reader = command.ExecuteReader();

                if (!reader.Read())
                {
                    return(null);
                }

                var maintenanceobj = new MaintenanceDTO()
                {
                    MaintenanceID = reader.GetInt32("MaintenanceID"),
                    BusID         = reader.GetInt32("BusID"),
                    TimeRepaired  = reader.GetDateTime("TimeRepaired"),
                    RepairedBy    = reader.GetInt32("RepairedBy"),
                    Type          = reader.GetInt32("Type"),
                    Status        = reader.GetInt32("Status")
                };
                return(maintenanceobj);
            }
        }
        public async void Post_CreateMaintenance_ShouldWork()
        {
            var expected = new MaintenanceDTO();
            var createMaintenanceRequest = new CreateMaintenanceRequest()
            {
                Date    = DateTime.Now,
                Service = "service"
            };

            var mediatorMock = new Mock <IMediator>();
            var logger       = new Mock <ILogger <CarController> >();

            mediatorMock.Setup(t => t.Send(It.IsAny <CreateMaintenanceCommand>(), It.IsAny <CancellationToken>()))
            .Returns(() => Task.FromResult(expected));

            var controller = new CarController(mediatorMock.Object, logger.Object);

            ValidateModelState(createMaintenanceRequest, controller);
            var response = await controller.Post(Guid.NewGuid(), createMaintenanceRequest);

            var okResult    = Assert.IsType <CreatedResult>(response);
            var maintenance = Assert.IsAssignableFrom <MaintenanceDTO>(okResult.Value);

            Assert.Equal(expected, maintenance);
        }
        /// <summary>
        /// UPDATE
        /// </summary>
        /// <param name="maintenanceDto"></param>
        /// <returns></returns>
        public MaintenanceDTO UpdateMaintenance(MaintenanceDTO maintenanceDto)
        {
            Maintenance maintenance = _mapper.Map <Maintenance>(maintenanceDto);

            _dbContext.Entry(maintenance).State = EntityState.Modified;

            _dbContext.SaveChanges();

            return(_mapper.Map <MaintenanceDTO>(maintenance));
        }
        /// <summary>
        /// CREATE MAINTENANCE
        /// </summary>
        public MaintenanceDTO CreateMaintenance(MaintenanceDTO maintenanceDto)
        {
            Maintenance maintenance = _mapper.Map <Maintenance>(maintenanceDto);

            maintenance.Id = new Guid();

            _dbContext.Maintenances.Add(maintenance);

            _dbContext.SaveChanges();

            return(_mapper.Map <MaintenanceDTO>(maintenance));
        }
示例#6
0
 public void AddTramToCleaning(ConductorView Train)
 {
     if (Train.Cleaning == true)
     {
         CleaningDTO cleaning = new CleaningDTO()
         {
             TramNumber = Train.TramNumber, Annotation = "de tram licht vol met bierblikjes van carnaval."
         };
         DataBase.AddCleaning(cleaning);
     }
     if (Train.Maintenance == true)
     {
         MaintenanceDTO maintenance = new MaintenanceDTO()
         {
             TramNumber = Train.TramNumber, Annotation = "de trams remmen maken een gek geluid"
         };
         DataBase.AddService(maintenance);
     }
 }
示例#7
0
 public bool RemoveService(MaintenanceDTO maintenance)
 {
     try
     {
         _connect.Con.Open();
         MySqlCommand cmd = _connect.Con.CreateCommand();
         cmd.CommandText = "DELETE FROM service WHERE idTram = (SELECT idTram FROM Tram WHERE Number = @TramNumber)";
         //TODO: require AuthKey
         cmd.Parameters.AddWithValue("@TramNumber", maintenance.TramNumber);
         cmd.ExecuteNonQuery();
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         _connect.Con.Close();
     }
     return(true);
 }
示例#8
0
 private bool RemoveService(MaintenanceView maintenanceView)
 {
     try
     {
         var service = new MaintenanceDTO();
         service.TramNumber = maintenanceView.TargetNumber;
         service.AuthKey    = maintenanceView.Key;
         if (this.DatabaseMaintenance.RemoveService(service))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
示例#9
0
        public List <MaintenanceDTO> GetServiceList()
        {
            List <MaintenanceDTO> maintenanceList = new List <MaintenanceDTO>();

            try
            {
                _connect.Con.Open();
                string query = "SELECT Tram.Number, service.Size, service.Priority, service.Description FROM service"
                               + " INNER JOIN Tram ON Tram.idTram = service.idTram";

                MySqlCommand cmd        = new MySqlCommand(query, _connect.Con);
                var          dataReader = cmd.ExecuteReader();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        MaintenanceDTO maintenance = new MaintenanceDTO
                        {
                            TramNumber = dataReader.GetInt32("Number"),
                            Annotation = dataReader.GetString("Description"),
                            Urgent     = dataReader.GetBoolean("Priority")
                        };
                        maintenanceList.Add(maintenance);
                    }
                }
                dataReader.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                _connect.Con.Close();
            }
            return(maintenanceList);
        }
示例#10
0
        public bool Create(MaintenanceDTO maintenanceDTO)
        {
            using var connection = Connection.GetConnection();
            {
                try
                {
                    using var command = connection.CreateCommand();

                    command.CommandText = "INSERT INTO Maintenance(BusID, RepairedBy, TimeRepaired, Type, Status) VALUES(@busID, @repairedBy, @timeRepaired, @type, @status);";
                    command.Parameters.AddWithValue("@busID", maintenanceDTO.BusID);
                    command.Parameters.AddWithValue("@repairedBy", maintenanceDTO.RepairedBy);
                    command.Parameters.AddWithValue("@timeRepaired", maintenanceDTO.TimeRepaired);
                    command.Parameters.AddWithValue("@type", maintenanceDTO.Type);
                    command.Parameters.AddWithValue("@status", maintenanceDTO.Status);

                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                    return(true);
                }
                catch { connection.Close(); return(false); }
            }
        }
示例#11
0
 public bool AddService(MaintenanceDTO maintenance)
 {
     try
     {
         _connect.Con.Open();
         MySqlCommand cmd = _connect.Con.CreateCommand();
         cmd.CommandText = "INSERT INTO `service` (`idTram`, `Size`, `Priority`, `Description`) VALUES ((SELECT idTram FROM Tram WHERE Number = @TramNumber), @Size, @Priority, @Description)";
         cmd.Parameters.AddWithValue("@TramNumber", maintenance.TramNumber);
         cmd.Parameters.AddWithValue("@Size", "1");
         cmd.Parameters.AddWithValue("@Priority", maintenance.Urgent);
         cmd.Parameters.AddWithValue("@Description", maintenance.Annotation);
         cmd.ExecuteNonQuery();
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         _connect.Con.Close();
     }
     return(true);
 }
示例#12
0
 public bool IndicateCompleteService(MaintenanceView maintenanceView)
 {
     try
     {
         MaintenanceDTO service = new MaintenanceDTO();
         service.TramNumber = maintenanceView.TargetNumber;
         service.AuthKey    = maintenanceView.Key;
         service.Annotation = maintenanceView.TargetAnnotation;
         if (this.DatabaseMaintenance.IndicateCompleteService(service))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
示例#13
0
 public bool IndicateCompleteService(MaintenanceDTO maintenance)
 {
     try
     {
         _connect.Con.Open();
         MySqlCommand cmd = _connect.Con.CreateCommand();
         cmd.CommandText = "INSERT INTO `servicehistory` (`idTram`, `idUser`, `ServiceDate`, `Description`) VALUES ((SELECT idTram FROM Tram WHERE Number = @TramNumber), (SELECT idUser FROM authorisationlist WHERE UniqueKey = @AuthKey), @Date, @Annotation)";
         cmd.Parameters.AddWithValue("@TramNumber", maintenance.TramNumber);
         cmd.Parameters.AddWithValue("@AuthKey", maintenance.AuthKey);
         cmd.Parameters.AddWithValue("@Annotation", maintenance.Annotation);
         cmd.Parameters.AddWithValue("@Date", DateTime.Now);
         cmd.ExecuteNonQuery();
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         _connect.Con.Close();
     }
     RemoveService(maintenance);
     return(true);
 }
示例#14
0
 public void Update(MaintenanceDTO item)
 {
     //item.TimeStamps = DateTime.Now;
     _unitOfWork.EFRepository <Maintenance>().Update(_mapper.Map <Maintenance>(item));
 }
示例#15
0
 public void Create(MaintenanceDTO item)
 {
     item.Id = Guid.NewGuid().ToString();
     //item.TimeStamps = DateTime.Now;
     _unitOfWork.EFRepository <Maintenance>().CreateAsync(_mapper.Map <Maintenance>(item));
 }
示例#16
0
 public MaintenanceDTO AddMaintenance(MaintenanceDTO maintenanceDto)
 {
     return(_manager.CreateMaintenance(maintenanceDto));
 }
示例#17
0
 public MaintenanceDTO UpdateMaintenance(MaintenanceDTO maintenanceDto)
 {
     return(_manager.UpdateMaintenance(maintenanceDto));
 }