コード例 #1
0
        public List <ObservationFilterViewModel> GetAllMeasurementsFromPerson(Person person)
        {
            List <ObservationFilterViewModel> observationsList = new List <ObservationFilterViewModel>();

            foreach (var observation in dbContext.Observations)
            {
                if (observation.Person == person)
                {
                    ObservationFilterViewModel model = new ObservationFilterViewModel();

                    var newObservation = dbContext.Observations.Where(o => o.Id.Equals(observation.Id))
                                         .Include(m => m.MainCategory)
                                         .Include(p => p.Person)
                                         .FirstOrDefault();
                    var measurementsList = dbContext.Measurements.Where(m => m.observationId.Equals(observation.Id))
                                           .Include(y => y.ThirdCategory)
                                           .ToList();

                    model.Observation  = newObservation;
                    model.Measurements = measurementsList;
                    model.Category     = dbContext.Categories.Where(c => c.Id.Equals(measurementsList[0].categoryId)).FirstOrDefault();
                    model.Measurement  = dbContext.Measurements.Where(m => m.Id.Equals(measurementsList[0].Id)).FirstOrDefault();

                    if (model.Measurements[0].ThirdCategory == null)
                    {
                        //Tomt objekt för att slippa få "null reference"
                        model.Measurements[0].ThirdCategory = new ThirdCategory();
                    }

                    observationsList.Add(model);
                }
            }
            return(observationsList);
        }
コード例 #2
0
        public ObservationFilterViewModel GetObservationWithMeasurement(int id)
        {
            var model = new ObservationFilterViewModel();

            var newObservation = dbContext.Observations.Where(o => o.Id.Equals(id))
                                 .Include(m => m.MainCategory)
                                 .Include(p => p.Person)
                                 .FirstOrDefault();
            var measurementsList = dbContext.Measurements.Where(m => m.observationId.Equals(id))
                                   .Include(y => y.ThirdCategory)
                                   .ToList();

            model.Observation  = newObservation;
            model.Measurements = measurementsList;
            model.Category     = dbContext.Categories.Where(c => c.Id.Equals(measurementsList[0].categoryId)).FirstOrDefault();
            model.Measurement  = dbContext.Measurements.Where(m => m.Id.Equals(measurementsList[0].Id)).FirstOrDefault();

            if (model.Measurements[0].ThirdCategory == null)
            {
                //Tomt objekt för att slippa få "null reference"
                model.Measurements[0].ThirdCategory = new ThirdCategory();
            }

            return(model);
        }
コード例 #3
0
        public async Task <IActionResult> PostEditUserObservation(ObservationFilterViewModel model, int measurmentValue, int measurmentId) //Measurement model
        {
            string fileName = null;

            if (model.CreateMeasurementViewModel.Photo != null)
            {
                string uploadsFolder = Path.Combine(hostingenv.WebRootPath, "pictures");
                fileName = Guid.NewGuid().ToString() + "_" + model.CreateMeasurementViewModel.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, fileName);
                model.CreateMeasurementViewModel.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                observationdb.UpdateMeasurementPhoto(measurmentId, fileName);
            }

            observationdb.UpdateObservation(model.Observation);

            if (!measurmentValue.Equals(0) && !measurmentId.Equals(0))
            {
                observationdb.UpdateMeasurmentValue(measurmentId, measurmentValue.ToString());
            }
            var user = await GetCurrentUserAsync();

            string userId = user?.Id;
            var    person = db.GetPersonFromObservationId(model.Observation.Id);

            if (person.IdentityId == userId)
            {
                return(RedirectToAction("UserProfile"));
            }
            else
            {
                return(RedirectToAction("EditUser", "Admin", new { id = person.IdentityId }));
            }
        }