public void UpdateMetricType(Guid accountId, UpdateMetricTypeRequestData data) { if (data == null) { throw new ArgumentNullException("data"); } if (string.IsNullOrWhiteSpace(data.SystemName)) { throw new UserFriendlyException("Не указан SystemName"); } if (string.IsNullOrWhiteSpace(data.DisplayName)) { data.DisplayName = data.SystemName; } var cache = new AccountCache(accountId); using (var metricType = cache.MetricTypes.Write(data.MetricTypeId)) { metricType.SystemName = data.SystemName; metricType.DisplayName = data.DisplayName; metricType.ConditionRed = data.AlarmCondition; metricType.ConditionYellow = data.WarningCondition; metricType.ConditionGreen = data.SuccessCondition; metricType.ElseColor = data.ElseColor; metricType.NoSignalColor = data.NoSignalColor; metricType.ActualTime = TimeSpanHelper.FromSeconds(data.ActualTimeSecs); metricType.BeginSave(); } cache.MetricTypes.Read(data.MetricTypeId).WaitSaveChanges(); }
public ActionResult Edit(EditModel model) { if (model.NoSignalColor.Checked == false) { ModelState.AddModelError("NoSignalColor", "Выберите цвет"); } if (!ModelState.IsValid) { return(View(model)); } Guid metricTypeId; var client = GetDispatcherClient(); if (model.Id.HasValue) { metricTypeId = model.Id.Value; var noSignalColor = model.NoSignalColor.GetSelectedColors().Single(); var updateData = new UpdateMetricTypeRequestData() { MetricTypeId = metricTypeId, SystemName = model.SystemName, DisplayName = model.DisplayName, AlarmCondition = model.ConditionRed, WarningCondition = model.ConditionYellow, SuccessCondition = model.ConditionGreen, ElseColor = model.ElseColor.GetSelectedOne(), ActualTimeSecs = TimeSpanHelper.GetSeconds(model.ActualTime), NoSignalColor = noSignalColor }; client.UpdateMetricType(CurrentUser.AccountId, updateData).Check(); } else { var createData = new CreateMetricTypeRequestData() { SystemName = model.SystemName, DisplayName = model.DisplayName, AlarmCondition = model.ConditionRed, WarningCondition = model.ConditionYellow, SuccessCondition = model.ConditionGreen, ElseColor = model.ElseColor.GetSelectedOne(), NoSignalColor = model.NoSignalColor.GetSelectedColors().SingleOrDefault(), ActualTimeSecs = TimeSpanHelper.GetSeconds(model.ActualTime) }; var response = client.CreateMetricType(CurrentUser.AccountId, createData); response.Check(); metricTypeId = response.Data.MetricTypeId; } return(RedirectToAction("Show", new { id = metricTypeId })); }
public UpdateMetricTypeResponse UpdateMetricType(Guid accountId, UpdateMetricTypeRequestData data) { if (data == null) { throw new ArgumentNullException("data"); } var request = GetRequest <UpdateMetricTypeRequest>(accountId); request.Data = data; var dispatcher = DispatcherHelper.GetDispatcherService(); return(dispatcher.UpdateMetricType(request)); }