Beispiel #1
0
 public ActionResult SavePointMeterLineItem(PointMeterLineItemModel model)
 {
     if (ModelState.IsValid)
     {
         var pointMeterLineItem = _pointMeterLineItemRepository.GetById(model.Id);
         pointMeterLineItem.IsNew = false;
         if (model.ReadingValue.HasValue)
         {
             var newReading = new Reading();
             newReading.ReadingValue              = model.ReadingValue;
             newReading.DateOfReading             = model.DateOfReading;
             newReading.ReadingSource             = (int?)ReadingSource.Directly;
             pointMeterLineItem.LastDateOfReading = model.DateOfReading;
             pointMeterLineItem.LastReadingValue  = model.ReadingValue;
             pointMeterLineItem.Readings.Add(newReading);
             //Check and create a new meter event history if the reading value does not in the range of the list of meter events
             _meterService.CreateMeterEventHistory(pointMeterLineItem, newReading);
         }
         pointMeterLineItem.MeterId         = model.MeterId;
         pointMeterLineItem.LastReadingUser = this._workContext.CurrentUser.Name;
         _pointMeterLineItemRepository.Update(pointMeterLineItem);
         this._dbContext.SaveChanges();
         return(new NullJsonResult());
     }
     else
     {
         return(Json(new { Errors = ModelState.Errors().ToHtmlString() }));
     }
 }