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() })); } }
/// <summary> /// Create PointMeterLineItem for Asset or Location /// ONLY assetId != null OR locationId != null /// </summary> public ActionResult CreatePointMeterLineItem(long pointId, long?assetId, long?locationId) { var point = _pointRepository.GetAll() .Where(p => (assetId != null && p.AssetId == assetId) || (locationId != null && p.LocationId == locationId)) .FirstOrDefault(); if (point == null) { point = new Point { AssetId = assetId, LocationId = locationId }; _pointRepository.Insert(point); } var pointMeterLineItem = new PointMeterLineItem { IsNew = true, Point = point }; var maxDisplayOrder = _pointMeterLineItemRepository.GetAll().Where(p => p.PointId == pointId).Max(p => (int?)p.DisplayOrder) ?? 0; pointMeterLineItem.DisplayOrder = maxDisplayOrder + 1; _pointMeterLineItemRepository.Insert(pointMeterLineItem); this._dbContext.SaveChanges(); var model = new PointMeterLineItemModel(); model = pointMeterLineItem.ToModel(); var html = this.PointMeterLineItemPanel(model); return(Json(new { Id = pointMeterLineItem.Id, pointId = point.Id, Html = html })); }
public static PointMeterLineItem ToEntity(this PointMeterLineItemModel model) { return(model.MapTo <PointMeterLineItemModel, PointMeterLineItem>()); }
public static PointMeterLineItem ToEntity(this PointMeterLineItemModel model, PointMeterLineItem destination) { return(model.MapTo(destination)); }
public string PointMeterLineItemPanel(PointMeterLineItemModel model) { var html = this.RenderPartialViewToString("_PointMeterLineItemDetails", model); return(html); }