public Reading Create(ReadingViewModel toCreate, bool save = true) { var reading = new Reading() { TripId = toCreate.TripId, AirIntakeTemperature = toCreate.AirIntakeTemperature, AmbientAirTemperature = toCreate.AmbientAirTemperature, EngineCoolantTemperature = toCreate.EngineCoolantTemperature, EngineRpm = toCreate.EngineRpm, FuelLevel = toCreate.FuelLevel, FuelType = toCreate.FuelType, Latitude = toCreate.Latitude, Longitude = toCreate.Longitude, MassAirFlow = toCreate.MassAirFlow, OilTemperature = toCreate.OilTemperature, ReadDate = toCreate.ReadDate, Speed = toCreate.Speed, ThrottlePosition = toCreate.ThrottlePosition }; _db.Readings.Add(reading); if (save) { _db.SaveChanges(); } return(reading); }
public async Task <ActionResult> Correction([Bind(Include = "ReadingId,ReadingValue,CorrectionValue")] ReadingViewModel reading) { var readingModel = await db.Readings.FindAsync(reading.ReadingId); if (readingModel != null) { if (readingModel.ReadingValue == reading.ReadingValue) { if (readingModel.ReadingValue != reading.CorrectionValue) { readingModel.CorrectedBy = User.Identity.Name; readingModel.CorrectionValue = reading.CorrectionValue; readingModel.LastEditDate = DateTime.Now; readingModel.LastEditedBy = User.Identity.Name; db.Entry(readingModel).State = EntityState.Modified; await db.SaveChangesAsync(); TempData.Clear(); TempData.Add("ReadingId", reading.ReadingId); return(RedirectToAction("Index", "Readings")); } ViewBag.Error = "The Correction Value must not be equal to the reading value"; return(View(reading)); } ViewBag.Error = "Invalid Form Data!"; return(View(reading)); } return(View(reading)); }
public IActionResult Delete([FromForm] int id) { var model = new ReadingViewModel(); model.Delete(id); return(LocalRedirect("/Admin/Reading/Index")); }
public ActionResult Index(string option) { if (option != null) { switch (option.ToLower()) { case "wordform": { _viewModel = new WordFormViewModel(); CreateLayoutView("Từ vựng"); break; } case "listening": { _viewModel = new ListeningViewModel(); CreateLayoutView("Tập nghe"); break; } case "reading": { _viewModel = new ReadingViewModel(); CreateLayoutView("Tập đọc"); break; } case "grammar": { _viewModel = new GrammarViewModel(); CreateLayoutView("Ngữ pháp"); break; } case "multiplechoice": { _viewModel = new MultipleChoiceViewModel(); CreateLayoutView("Trắc nghiệm"); break; } default: { _viewModel = new LearningViewModel(); CreateLayoutView("Tự học"); break; } } } else { _viewModel = new LearningViewModel(); CreateLayoutView("Tự học"); ViewBag.page = "Index"; return(View(_viewModel)); } return(View("Index", "~/Views/Layout/_LearningLayout.cshtml", _viewModel)); }
public IActionResult Index() { ReadingViewModel model = new ReadingViewModel(); model.LoadTenant(); model.GetDropDownList(); return(View(model)); }
public IActionResult getreadings(int id) { var tableModel = new DataTablesAjaxRequestModel(Request); var model = new ReadingViewModel(); var data = model.GetReadings(tableModel); return(Json(data)); }
public ActionResult Reading() { ReadingViewModel model = new ReadingViewModel(); model.Reading = this.BlogConfiguration.ReadingConfiguration.MapTo <ReadingConfigurationBinder>(); return(this.View(model)); }
protected internal override void OnCreate(object parameter) { base.OnCreate(parameter); if (parameter is ReadingViewModel viewModel) { ViewModel = viewModel; } SizeChanged += ReadingActivity_SizeChanged; _display = new DisplayRequest(); }
internal async void Readings_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (Reading reading in e.NewItems.OfType <Reading>()) { var read = new ReadingViewModel() { Title = reading.Title, Value = reading.Value, Unit = reading.Unit } as T; Collection.Add(read); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (Reading reading in e.OldItems.OfType <Reading>()) { var readerVM = Collection.FirstOrDefault(x => (x as ReadingViewModel).Title == reading.Title); if (readerVM != null) { Collection.Remove(readerVM); } } } else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace) { //foreach(Device oldDevice in e.OldItems) for (int i = 0; i < e.OldItems.Count; i++) { var oldReadVM = Collection.FirstOrDefault(x => (x as ReadingViewModel).Title == ((Reading)e.OldItems[i]).Title); if (oldReadVM != null) { var newRead = (Reading)e.NewItems[i]; int index = Collection.IndexOf(oldReadVM); Collection[index] = new ReadingViewModel() { Title = newRead.Title, Value = newRead.Value, Unit = newRead.Unit } as T; SelectedItem = Collection[index]; } } } else if (e.Action == NotifyCollectionChangedAction.Reset) { Collection.Clear(); } }); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); DataContext = e.Parameter; if (e.Parameter is ReadingViewModel readingViewModel) { ViewModel = readingViewModel; ViewModel.Init(); } _display.RequestActive(); Window.Current.SetTitleBar(TitleBarBorder); }
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { // Load Images try { readyForConnectedAnimation = false; var galleryLinkFromLastPage = QueryString.Parse(e.NavigationParameter as string)["link"]; // Get ExGallery if (App.Current.Resources.ContainsKey("Gallery")) { this.ReadingViewModel = new ReadingViewModel(App.Current.Resources["Gallery"] as ExGallery); } else { this.ReadingViewModel = new ReadingViewModel(await ExGallery.DownloadGalleryAsync(galleryLinkFromLastPage, 1, 3)); } this.ReadingViewModel.CurrentImageIndex = -1; flipView.SelectedIndex = -1; // Jump to Page indexFromLastPage = int.Parse(QueryString.Parse(e.NavigationParameter as string)["page"]); if (this.ReadingViewModel.CurrentImageIndex != indexFromLastPage) { readyForConnectedAnimation = true; this.ReadingViewModel.CurrentImageIndex = indexFromLastPage; } else { // Handle the connected animation flipView.UpdateLayout(); HandleConnectedAnimation(); } } catch (Exception ex) { } }
public static ReadingViewModel ToViewModel(this Reading reading) { var vm = new ReadingViewModel() { Id = reading.ReadingId, ReadDate = reading.ReadDate, TripId = reading.TripId, Latitude = reading.Latitude, Longitude = reading.Longitude, AirIntakeTemperature = reading.AirIntakeTemperature, AmbientAirTemperature = reading.AmbientAirTemperature, EngineCoolantTemperature = reading.EngineCoolantTemperature, OilTemperature = reading.OilTemperature, EngineRpm = reading.EngineRpm, Speed = reading.Speed, MassAirFlow = reading.MassAirFlow, ThrottlePosition = reading.ThrottlePosition, FuelType = reading.FuelType, FuelLevel = reading.FuelLevel }; return(vm); }
public ActionResult Reading(ReadingConfigurationBinder reading) { if (!ModelState.IsValid) { ReadingViewModel model = new ReadingViewModel(); model.Reading = reading; } try { var configuration = this.BlogConfiguration; configuration.ReadingConfiguration = reading.MapTo <ReadingConfiguration>(); this.ConfigurationService.SaveOrUpdateConfiguration(configuration); return(this.urlBuilder.Admin.FeedbackPage(FeedbackType.Positive, "Configuration Saved", this.urlBuilder.Admin.EditSeoConfiguration()).Redirect()); } catch (DexterException e) { this.Logger.ErrorFormat("Unable to save the specified category", e); return(this.urlBuilder.Admin.FeedbackPage(FeedbackType.Negative, "Configuration Not Saved", this.urlBuilder.Admin.EditSeoConfiguration()).Redirect()); } }
public async Task <IHttpActionResult> PostReading(ReadingViewModel reading) { var currentEmployee = db.Users.Include(x => x.EmployeeDetails).FirstOrDefault(x => x.UserName == reading.UserName); if (currentEmployee != null) { var readingModel = new Reading { Accuracy = reading.Accuracy, Altitude = reading.Altitude, AltitudeAccuracy = reading.AltitudeAccuracy, MeterId = reading.MeterId, DateCreated = DateTime.Now, CreatedBy = currentEmployee.UserName, EmployeeId = currentEmployee.EmployeeDetails.EmployeeId, Speed = reading.Speed, ReadingValue = reading.ReadingValue, ReadingId = IdentityGenerator.NewSequentialGuid(), Longitude = reading.Longitude, Latitude = reading.Latitude, Heading = reading.Heading, LocationDateTime = DateTime.Now, IsConfirmed = false, }; //Fix Meter Issue var previousReading = await db.Readings.Where(x => x.MeterId == reading.MeterId).OrderByDescending(x => x.DateCreated).FirstOrDefaultAsync(); if (previousReading != null) { if (readingModel.ReadingValue >= previousReading.ReadingValue) { readingModel.PreviousReading = previousReading; } else { return(Conflict()); } } try { db.Readings.Add(readingModel); await db.SaveChangesAsync(); //Update ViewModel reading.DateCreated = readingModel.DateCreated; reading.ReadingId = readingModel.ReadingId; reading.CreatedBy = readingModel.CreatedBy; reading.EmployeeId = readingModel.EmployeeId; return(CreatedAtRoute("DefaultApi", new { id = reading.ReadingId }, reading)); } catch (DbUpdateException ex) { return(Conflict()); } catch (Exception ex) { return(BadRequest(ex.Message)); } } return(NotFound()); }
public ActionResult Reading() { _viewModel = new ReadingViewModel(); return(PartialView("_Reading", ReadingViewModel)); }
public PageInfo <ReadingViewModel> GetReadingData(int buildingId, int?objectId, int?datafieldId, string startTime, string endTime, int page, int size) { PageInfo <ReadingViewModel> res, req; IEnumerable <ReadingViewModel> response; req = new PageInfo <ReadingViewModel>(page, size, startTime, endTime); try { IEnumerable <Reading> filtered; var sql = ""; object sqlParams = null; if (objectId != null && datafieldId != null) { if (req.Size >= 365) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('month', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND ObjectId=@ObjectId AND DataFieldId=@DataFieldId group by 1,2"; } else if (req.Size >= 180) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('week', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND ObjectId=@ObjectId AND DataFieldId=@DataFieldId group by 1,2"; } else { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName, rv.Timestamp, rv.Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND ObjectId=@ObjectId AND DataFieldId=@DataFieldId"; } sqlParams = new { StartTime = req.StartDate, EndTime = req.EndDate, BuildingId = buildingId, ObjectId = objectId, DataFieldId = datafieldId }; } else if (objectId == null && datafieldId != null) { if (req.Size >= 365) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('month', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND DatafieldId=@DataFieldId group by 1,2"; } else if (req.Size >= 180) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('week', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND DatafieldId=@DataFieldId group by 1,2"; } else { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName, rv.Timestamp, rv.Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND DataFieldId=@DataFieldId"; } sqlParams = new { StartTime = req.StartDate, EndTime = req.EndDate, BuildingId = buildingId, DataFieldId = datafieldId }; } else if (objectId != null && datafieldId == null) { if (req.Size >= 365) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('month', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND ObjectId=@ObjectId group by 1,2"; } else if (req.Size >= 180) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('week', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND ObjectId=@ObjectId group by 1,2"; } else { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , rv.Timestamp, rv.Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId AND ObjectId=@ObjectId"; } sqlParams = new { StartTime = req.StartDate, EndTime = req.EndDate, BuildingId = buildingId, ObjectId = objectId }; } else { if (req.Size >= 365) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('month', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId group by 1,2"; } else if (req.Size >= 180) { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , date_trunc('week', rv.Timestamp::timestamp) AS Timestamp, avg(rv.Value) as Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId group by 1,2"; } else { sql = @"SELECT obj.Name || ' ' || df.Name DatapointName , rv.Timestamp, rv.Value FROM " + _readingConfig.ReadingTableName + @" rv left join Object obj on obj.Id=rv.ObjectId inner join DataField df on df.Id =rv.DataFieldId WHERE Timestamp BETWEEN @StartTime AND @EndTime AND BuildingId=@BuildingId"; } sqlParams = new { StartTime = req.StartDate, EndTime = req.EndDate, BuildingId = buildingId, ObjectId = objectId }; } filtered = GetData <Reading>(sql, sqlParams, _dbContext).AsQueryable(); //================================================= List <ReadingViewModel> listReadings = new List <ReadingViewModel>(); List <string> dataPoints = filtered.Select(x => x.DatapointName).Distinct().ToList(); for (int i = 0; i < dataPoints.Count; i++) { List <long> unixList = new List <long>(); List <decimal> values = new List <decimal>(); var datapointData = filtered.Where(x => x.DatapointName == dataPoints[i]).OrderBy(x => x.Timestamp); var obj = new ReadingViewModel(); obj.BuildingName = _buildingRepositories.GetBuildingById(buildingId).Name; foreach (var item in datapointData) { unixList.Add(DatTimeToUnix(Convert.ToDateTime(item.Timestamp))); values.Add(Convert.ToDecimal(item.Value)); } obj.DatapointName = dataPoints[i].ToString(); obj.Timestamp = unixList; obj.Value = values; listReadings.Add(obj); } //================================================= response = listReadings; res = new PageInfo <ReadingViewModel>(response, req.TotalCount, req.Size); return(res); } catch (Exception ex) { response = new List <ReadingViewModel>().AsQueryable(); return(res = new PageInfo <ReadingViewModel>(response, 0, size)); } }