public IActionResult GridView() { var model = this._dbContext.Measurement.Select(x => new Models.Measurement { Temperature = x.Temperature, Humidity = x.Humidity, Weight = x.Weight, Depth = x.Depth, Width = x.Width, Lenght = x.Lenght, MeasurmentCatagory = x.Catagory, Pass = x.Pass, MeasurementId = x.MeasurementId }); Models.Measurement calc = new Models.Measurement(); double TemperatureSum = calc.CalculateSum(model.Select(x => x.Temperature).ToList()); double TemperatureAverage = calc.CalculateMean(model.Select(x => x.Temperature).ToList()); double TemperatureMin = calc.CalculateMin(model.Select(x => x.Temperature).ToList()); double TemperatureMax = calc.CalculateMax(model.Select(x => x.Temperature).ToList()); double TemperatureStdv = calc.CalculateStdv(model.Select(x => x.Temperature).ToList()); double TemperatureVariance = calc.CalculateVar(model.Select(x => x.Temperature).ToList()); ViewBag.TemperatureSum = TemperatureSum; ViewBag.TemperatureAverage = TemperatureAverage; ViewBag.TemperatureMin = TemperatureMin; ViewBag.TemperatureMax = TemperatureMax; ViewBag.TemperatureStdv = TemperatureStdv; ViewBag.TemperatureVariance = TemperatureVariance; IndexMeasurementViewModel viewModel = new IndexMeasurementViewModel { Items = model }; return(this.View(viewModel)); }
public IActionResult AddMeasurement(AddMeasurmentViewModel model) { var identity = User.Identity as ClaimsIdentity; var user = identity.Claims.FirstOrDefault(c => c.Type == "preferred_username")?.Value; var measurement = new Models.Measurement { Temperature = model.Temperature, Humidity = model.Depth, Weight = model.Weight , Depth = model.Depth, Width = model.Width, Lenght = model.Lenght, Pass = model.Pass, MeasurmentCatagory = model.ItemCatagory }; try { using (this._dbContext) { //This utilizes the stored Proc, but this is currently not working. Might need further investigation //var result = this._dbContext.Set<Entities.Measurement>().FromSqlRaw("EXECUTE [dbo].[AddMeasurement] @p0 @p1 @p2 @p3 @p4 @p5 @p5 @p6 @p7" // , measurement.Temperature, measurement.Humidity, measurement.Weight // , measurement.Depth, measurement.Width, measurement.Lenght, (int)measurement.MeasurmentCatagory, measurement.Pass); var personId = this._dbContext.Person.Select(x => new Person { PersonId = x.PersonId, PersonUsername = x.PersonUsername }).Where(x => x.PersonUsername.CompareTo(user) == 0); _ = this._dbContext.Measurement.Add(new Entities.Measurement { MeasurementId = new Guid(), Temperature = measurement.Temperature, Humidity = measurement.Humidity, Weight = measurement.Weight, Depth = measurement.Depth, Width = measurement.Width, Lenght = measurement.Lenght, Catagory = measurement.MeasurmentCatagory, Pass = measurement.Pass, PersonId = personId.Select(x => x.PersonId).FirstOrDefault() }); _ = this._dbContext.SaveChanges(); } } catch (Exception e) { return(this.View(new ErrorViewModel { RequestId = e.Message ?? this.HttpContext.TraceIdentifier })); } return(this.RedirectToAction("GridView", "Home")); }
public IActionResult EditMeasurment(EditMeasurmentViewModel model) { var identity = User.Identity as ClaimsIdentity; var user = identity.Claims.FirstOrDefault(c => c.Type == "preferred_username")?.Value; Models.Measurement measurement = new Models.Measurement { Temperature = model.Temperature, Humidity = model.Depth, Weight = model.Weight , Depth = model.Depth, Width = model.Width, Lenght = model.Lenght, Pass = model.Pass, MeasurmentCatagory = model.ItemCatagory }; try { using (this._dbContext) { //_ = this._dbContext.Measurement.FromSqlRaw("UpdateMeasurement @p0 @p1 @p2 @p3 @p4 @p5 @p5 @p6 @p7" // , model.MeasurementId, measurement.Temperature, measurement.Humidity, measurement.Weight // , measurement.Depth, measurement.Width, measurement.Lenght, (int) measurement.MeasurmentCatagory, measurement.Pass).ToList(); var personId = this._dbContext.Person.Select(x => new Person { PersonId = x.PersonId, PersonUsername = x.PersonUsername }).Where(x => x.PersonUsername.CompareTo(user) == 0); _ = this._dbContext.Measurement.Update(new Entities.Measurement { MeasurementId = model.MeasurementId, Temperature = measurement.Temperature, Humidity = measurement.Humidity, Weight = measurement.Weight, Depth = measurement.Depth, Width = measurement.Width, Lenght = measurement.Lenght, Catagory = measurement.MeasurmentCatagory, Pass = measurement.Pass, PersonId = personId.Select(x => x.PersonId).FirstOrDefault() }); _ = this._dbContext.SaveChanges(); } } catch (Exception e) { return(this.View(new ErrorViewModel { RequestId = e.Message ?? this.HttpContext.TraceIdentifier })); } return(this.RedirectToAction("GridView", "Home")); }
public async Task <IEnumerable <Measurement> > GetCurrentWeatherAllAsync(string[] cities) { List <Measurement> weatherList = new List <Measurement>(); var client = new HttpClient(); var collection = new DAL(_configuration); foreach (var city in cities) { string connectionString = _configuration.GetConnectionString("WeatherIO"); Task <string> getWeatherStringTask = client.GetStringAsync($"{connectionString + city}"); try { string weatherString = await getWeatherStringTask; var weatherData = JsonSerializer.Deserialize <Models.WeatherData>(weatherString); var measurement = new Models.Measurement { Id = Guid.NewGuid(), City = city, Date = DateTime.Now, Values = new Models.Values { RelativeHumidity = weatherData.data[0].rh, Temp = weatherData.data[0].temp, WindSpeed = weatherData.data[0].wind_spd, WindDir = weatherData.data[0].wind_dir, Uv = weatherData.data[0].uv, CloudCoverage = weatherData.data[0].clouds, App_Temp = weatherData.data[0].app_temp, Description = weatherData.data[0].weather.description } }; await collection.MeasurementCollection().InsertOneAsync(measurement); weatherList.Add(measurement); } catch { } } return(weatherList); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); //return RedirectToAction("Index", "Home"); //Noget jeg har tilføjet til koden!! Sunddk.Utilities.Calculate utilitie = new Utilities.Calculate(); double BMR = utilitie.CalculateBMR(model.DateOfBirth, model.Gender, model.Weight, model.Height); var measurment = new Models.Measurement(); measurment.Date = DateTime.Now.Date; measurment.Weight = model.Weight; measurment.Height = model.Height; measurment.BMR = BMR; using (var db = new Models.MealPlanContext()) { var Person = new Models.Person(); Person.Name = model.Name; Person.DateOfBirth = model.DateOfBirth; Person.IsAdmin = model.IsAdmin; Person.Gender = model.Gender; Person.Email = model.Email; Person.Password = model.Password; Person.Measurements = new List<Models.Measurement>(); Person.Measurements.Add(measurment); db.Persons.Add(Person); db.SaveChanges(); } return RedirectToAction("UserProfile", "User", new { Email = model.Email }); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public Models.Measurement AddNew(Models.Measurement measurement) { db.Measurements.Add(measurement); db.SaveChanges(); return(measurement); }
public void Insert(Models.Measurement measurement) { collection.InsertOneAsync(measurement.ToBsonDocument()); }