public async Task UpdateMachineActivity(MasiniForUpdate machineToUpdate, int id) { UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl) { Path = $"{ApiConstants.UpdateMachineEndpoint}/{id}" }; await _genericRepository.PutAsync(builder.ToString(), machineToUpdate); }
//private async Task UpdateJobFirstWrite(DateTime firstClick) //{ // try // { // if (Counter == 1) // { // var jobId = _settingsService.JobIdSettings; // var job = await _jobService.GetJob(jobId); // job.FirstWrite = firstClick; // await _jobService.UpdateJob(jobId, job); // } // } // catch (Exception e) // { // Console.WriteLine(e); // throw; // } //} private async Task UpdateJobLastWrite(bool isStop) { try { var job = await _jobService.GetJob(_settingsService.JobIdSettings); var machine = await _masiniService.GetMachineAsync(_settingsService.MachineIdSettings); var lastWrite = await _jobService.GetLastClickForJob(_settingsService.JobIdSettings); var currentTime = await _jobService.GetServerDateTime(); DateTime initialdate = DateTime.ParseExact("11/11/2011 00:00:00", "dd/MM/yyyy hh:mm:ss", null); if (lastWrite == initialdate) { job.LastWrite = currentTime; job.Closed = currentTime; } else if (DateTime.Parse(_settingsService.UserLoginDateSettings).Day != currentTime.Day) { job.LastWrite = lastWrite; job.Closed = lastWrite; } else { job.LastWrite = lastWrite; job.Closed = currentTime; } await _jobService.UpdateJob(job.Id.ToString(), job); //await AddEfficiencyForJob(job); if (machine.Active && isStop) { MasiniForUpdate machineToUpdate = new MasiniForUpdate() { Id = machine.Id, Occupied = false, Active = false }; await _masiniService.UpdateMachineActivity(machineToUpdate, machineToUpdate.Id); } _settingsService.JobIdSettings = null; _settingsService.JobNormSettings = null; _settingsService.CounterSettings = null; _settingsService.OneClickWorthSettings = null; _settingsService.IsNormCalculatedSettings = null; _settingsService.TotalEfficiencySettings = null; _settingsService.SelectedPhaseSettings = null; _settingsService.LastClickSetting = null; // MessagingCenter.Send(this, "disconnectFromBT"); await _navigationService.NavigateToAsync <HomeViewModel>(); } catch (Exception e) { await _dialogService.ShowDialog(e.Message, "Exception:UpdateJobLastWrite" + e, "OK"); } }
private async void MachineWithBarCode(string id) { IsBusy = true; if (_connectionService.IsConnected) { if (!string.IsNullOrWhiteSpace(_settingsService.UserNameSetting)) { var machine = await _machineService.GetMachineAsync(id); if (machine.Occupied) { await _navigationService.NavigateToAsync <MainViewModel>(); await _dialogService.ShowDialog( $"Two persons can't be logged on one machine at the same time!", "Machine is occupied!", "OK"); } else { if (machine.Linie.Contains(_settingsService.UserLineSettings)) { try { // we store the Id to know if the user is already logged in to the application _settingsService.MachineIdSettings = id; _settingsService.MachineCodeSettings = machine.CodMasina; _settingsService.MachineNameSettings = machine.Descriere; _settingsService.MachineLineSettings = machine.Linie; IsBusy = false; int.TryParse(id, out var machineId); MasiniForUpdate machineToUpdate = new MasiniForUpdate { Id = machineId, Occupied = true, Active = true, }; await _machineService.UpdateMachineActivity(machineToUpdate, machineId); await _navigationService.NavigateToAsync <MainViewModel>(); } catch (Exception e) { await _dialogService.ShowDialog(e.ToString(), "Exception", "OK"); } } else { await _navigationService.NavigateToAsync <MainViewModel>(); await _dialogService.ShowDialog( $"You selected wrong line. Scanned machine belong to {machine.Linie} and your selected line by manager is {_settingsService.UserLineSettings}. " + "Please contact your superior!", "Wrong line!", "OK"); } } } else { await _navigationService.NavigateToAsync <LoginViewModel>(); await _dialogService.ShowDialog( "First try to sing in, then you can scan the machine.", "Wrong barcode!", "OK"); } } else { await _navigationService.NavigateToAsync <MainViewModel>(); await _dialogService.ShowDialog( "Connection problem please try again later.", "Internet connection problem", "OK"); } }