private void LoadRepairLogs(long repairID) { technicianService.ParseDatabase(); var repairLogs = technicianService.RepairLogs.FindAll(l => l.Repair.Id == repairID); var topbar = new RepairLogEditorTopbar(); topbar.newBtn.Click += (object sender, RoutedEventArgs args) => { var logEntry = new RepairLogEntry(); logEntry.techIDLbl.Content = technicianService.CurrentTechnician.Id; logEntry.dobLbl.Content = DateTime.Now.ToShortDateString(); entryPanel.Children.Insert(0, logEntry); }; topbar.backBtn.Click += (object sender, RoutedEventArgs args) => { topbarpanel.Children.Clear(); entryPanel.Children.Clear(); LoadRepairs(); }; topbar.saveBtn.Click += (object sender, RoutedEventArgs args) => { foreach (UIElement uiElement in entryPanel.Children) { if (uiElement is RepairLogEntry) { var rle = (RepairLogEntry)uiElement; if (!rle.Modified) { continue; } var rlog = new RepairLogView(); rlog.Date = DateTime.Parse(rle.dobLbl.Content.ToString()); rlog.TechnicianId = Convert.ToInt64(rle.techIDLbl.Content.ToString()); rlog.Description = rle.logTblock.Text; rlog.Id = rle.LogId; rlog.Repair = technicianService.Repairs.FirstOrDefault(r => r.Id == repairID); technicianService.UploadRepairLog(rlog); } } }; topbarpanel.Children.Add(topbar); foreach (RepairLogView log in repairLogs) { var logEntry = new RepairLogEntry(); logEntry.techIDLbl.Content = log.TechnicianId.ToString(); logEntry.logTblock.Text = log.Description.ToString(); logEntry.dobLbl.Content = log.Date.ToShortDateString(); logEntry.LogId = log.Id; entryPanel.Children.Insert(0, logEntry); } topbar.repairIdLbl.Content = repairID.ToString(); }
public void AddRepairLog(RepairLogView log) { using var ctx = new WorkshopContext(); RepairLog newLog = new RepairLog(); newLog.Date = log.Date; newLog.Description = log.Description; newLog.Repair = ctx.Repairs.SingleOrDefault(r => r.Id == log.Repair.Id); newLog.TechnicianId = log.TechnicianId; ctx.RepairLogs.Add(newLog); ctx.SaveChanges(); }
public void UpdateRepairLog(RepairLogView log) { using var ctx = new WorkshopContext(); RepairLog updatedLog = ctx.RepairLogs.Single(rl => rl.Id == log.Id); updatedLog.Repair = ctx.Repairs.SingleOrDefault(r => r.Id == log.Repair.Id); updatedLog.Id = log.Id; updatedLog.Description = log.Description; updatedLog.Date = log.Date; updatedLog.TechnicianId = log.TechnicianId; ctx.RepairLogs.Update(updatedLog); ctx.SaveChanges(); }
public static RepairLogView GetViewModell(RepairLog rl) { RepairLogView rlv = new RepairLogView(); if (rl != null) { rlv.Id = rl.Id; rlv.Date = rl.Date; rlv.Description = rl.Description; rlv.Repair = GetViewModell(rl.Repair); rlv.TechnicianId = rl.TechnicianId; } return(rlv); }
public ActionResult AddRepairLog(RepairLogView log) { var workshopRepo = new WorkshopRepository(); if (workshopRepo.GetRepairLogs().SingleOrDefault(rl => rl.Id == log.Id) != null) { return(Ok()); } var repairRepo = workshopRepo.GetRepairs(); log.Repair = repairRepo.Single(r => r.Id == log.Repair.Id); workshopRepo.AddRepairLog(log); return(Ok()); }
public void UploadRepairLog(RepairLogView repair) { string URIPart = URIparts[typeof(RepairLogView)]; var options = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; var json = JsonConvert.SerializeObject(repair, options); var rawData = new StringContent(json, Encoding.UTF8, "application/json"); var result = httpClient.PutAsync(baseUri + URIPart, rawData).Result; if (!result.IsSuccessStatusCode) { MessageBox.Show(result.ReasonPhrase, result.StatusCode.ToString()); } }
public ActionResult UpdateRepairLog(RepairLogView log) { var workshopRepo = new WorkshopRepository(); RepairLogView found = workshopRepo.GetRepairLogs(log.Repair.Id).SingleOrDefault(rl => rl.Id == log.Id); if (found is null) { workshopRepo.AddRepairLog(log); } else { found.Date = DateTime.Today; found.Description = log.Description; found.TechnicianId = log.TechnicianId; workshopRepo.UpdateRepairLog(found); } return(Ok()); }
public void UploadRepairLog(RepairLogView rl) { workshopClient.UploadRepairLog(rl); }