예제 #1
0
        public IActionResult Add(IncomingJob incomingJob)
        {
            Job job = new Job()
            {
                Image            = incomingJob.Image,
                FileName         = incomingJob.FileName,
                StatusDateTime   = DbUtils.UnixTimeStampToDateTime(incomingJob.StatusTime),
                FilamentLength   = (int)incomingJob.FilamentLength,
                PrintLength      = (int)incomingJob.PrintLength,
                DeviceIdentifier = incomingJob.DeviceIdentifier,
                StatusMessage    = incomingJob.StatusMessage,
                PercentDone      = (int?)incomingJob.PercentDone,
                TimeLeft         = incomingJob.TimeLeft,
            };
            Printer currentPrinter = _printerRepository.GetPrinterByDeviceIdentifier(job.DeviceIdentifier);// add catch if not found

            job.PrinterId = currentPrinter.Id;
            Job lastJob = _jobRepository.GetLastPrinterJob(currentPrinter.Id);

            if (job.PercentDone == 100)
            {
                job.CompleteDateTime = DateTime.Now;
            }
            if (job.PercentDone > lastJob.PercentDone)
            {
                job.Id = lastJob.Id;
                _jobRepository.Update(job);
                return(Ok());
            }

            _jobRepository.Add(job);
            return(base.Created("", job));
        }
 public IActionResult GetPrinterByDeviceIdentifier(string deviceIdentifier)
 {
     return(Ok(_printerRepository.GetPrinterByDeviceIdentifier(deviceIdentifier)));
 }