public async Task <IActionResult> LogData(LogDataViewModel model) { // Retrieve requested metric var metric = await _metricService.GetOrCreateMetricAsync(Metrics.Log, model.Source); _context.Attach(metric); // Retrieve requested user action var logSeverity = await _context .LogEntrySeverities .FirstAsync(act => act.Id == model.MessageSeverity.AsInt()); // Record data await _context .LogDataPoints .AddAsync( new LogDataPoint { Severity = logSeverity, Count = model.Count, Metric = metric } ); // Submit changes to data provider await _context.SaveChangesAsync(); return(Ok("Data point has been recorded.")); }
public LogDataView(LogDataViewModel viewModel) { this.InitializeComponent(); this.DataContext = viewModel; viewModel.PropertyChanged += this.ViewModel_PropertyChanged; details.Content = LanguageData.Current.LogDataView_Details; copy.Content = LanguageData.Current.LogDataView_Copy; }
public MainWindow() { InitializeComponent(); TestAdbDeviceViewModel dvm = new TestAdbDeviceViewModel(); LogDataViewModel logDataVM = new LogDataViewModel(); dvm.LogDataReceived += logDataVM.ReceivedLogData; dvm.ClearLogDataEvent += logDataVM.ClearLogData; dvm.ViewModels.Add(logDataVM); this.DataContext = dvm; }
/// <summary> /// GET: Admin/Data/Log /// Log manual Production /// </summary> /// <returns>ActionResult.</returns> public ActionResult Log() { // Create an instance of the Data utility to get active objects and add them to view mdoel var data = new Data(); // We will pass through an instance of the view model var model = new LogDataViewModel(); // Add active objects to view model model.EmployeeList = data.GetActiveEmployees(); model.IssueList = data.GetActiveIssues(); model.ProductList = data.GetActiveProducts(); model.ProcessList = data.GetActiveProcesses(); model.BatchList = data.GetActiveBatches(); return(View(model)); }
public LogModuleView() { InitializeComponent(); DataContext = new LogDataViewModel(); }
public ActionResult Log(LogDataViewModel Model) { // Create an instance of the data utility var d = new Data(); if (Model.StartTime == null || Model.StartTime == "" || Model.StartTime.Count() != 10 || Model.StartTime.Length != 10) { TempData["Error"] = "Please enter a valid Date."; Model.EmployeeList = d.GetActiveEmployees(); Model.ProductList = d.GetActiveProducts(); Model.ProcessList = d.GetActiveProcesses(); Model.BatchList = d.GetActiveBatches(); Model.IssueList = d.GetActiveIssues(); Model.SelectedIssues = Model.SelectedIssues; return(View(Model)); } if (!ModelState.IsValid) { // Production log entry was invalid // Kick them back to the view and try again // But we have to rebuild the view model first Model.EmployeeList = d.GetActiveEmployees(); Model.ProductList = d.GetActiveProducts(); Model.ProcessList = d.GetActiveProcesses(); Model.BatchList = d.GetActiveBatches(); Model.IssueList = d.GetActiveIssues(); Model.SelectedIssues = Model.SelectedIssues; return(View(Model)); } // If we find that production indeed exists if (Model != null) { // Initialize a new Production object var production = new Production(); // Grab each property based on the selected value and add it to the new Production object production.Employee = db.Employees.Find(Model.EmployeeID); production.Product = db.Products.Find(Model.ProductID); production.Process = db.Processes.Find(Model.ProcessID); production.Batch = db.Batches.Find(Model.BatchID); production.Quantity = Model.Quantity; // Duration from manual logging is in HOURS // Measures are calcualted as MINUTES production.Duration = Model.Duration * 60; // Convert user-entered times to DateTimes for model and DB production.StartTime = Convert.ToDateTime(Model.StartTime); // DateRecorded is only not null if an Admin enters the production manually production.DateRecorded = Model.DateRecorded; production.EndTime = Convert.ToDateTime(Model.StartTime); // If any issue is selected if (Model.SelectedIssues != null && Model.SelectedIssues.Count() > 0) { // Insert a list of Issues as the production Issues where the ID is found within the Issues array production.Issues = db.Issues.Where(x => Model.SelectedIssues.Contains(x.IssueID.ToString())).ToList(); } System.Diagnostics.Debug.WriteLine("**********************************"); System.Diagnostics.Debug.WriteLine(Model.StartTime + " " + Model.StartTime.Length + " " + Model.StartTime.Count()); System.Diagnostics.Debug.WriteLine("**********************************"); db.Productions.Add(production); db.SaveChanges(); var ReturnModel = new LogDataViewModel(); // Inform the user that their data was successfully entered TempData["Success"] = "Production Logged"; // Rebuild the view model and send them back to the update view ReturnModel.EmployeeList = d.GetActiveEmployees(); ReturnModel.ProductList = d.GetActiveProducts(); ReturnModel.ProcessList = d.GetActiveProcesses(); ReturnModel.BatchList = d.GetActiveBatches(); ReturnModel.IssueList = d.GetActiveIssues(); return(View(ReturnModel)); } // Fillout the lists if we need to return to the update view Model.EmployeeList = d.GetActiveEmployees(); Model.ProductList = d.GetActiveProducts(); Model.ProcessList = d.GetActiveProcesses(); Model.BatchList = d.GetActiveBatches(); Model.IssueList = d.GetActiveIssues(); Model.SelectedIssues = Model.SelectedIssues; // Inform the user that the data was not entered successfully TempData["Error"] = "Production not updated"; return(View(Model)); }