public ActionResult UpdateWeeklyAlarm(HighlightViewModel viewModel)
 {
     var existingHighlight = _highlightService.GetHighlightByPeriode(new GetHighlightRequest
     {
         Date = viewModel.Date,
         HighlightTypeId = viewModel.TypeId
     });
     SaveHighlightRequest req = new SaveHighlightRequest();
     req.PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), viewModel.PeriodeType, true);
     req.Date = viewModel.Date.Value;
     req.TypeId = viewModel.TypeId;
     if (existingHighlight.Id == 0)
     {
         req.Message = "{\"period\" : \"\",\"processtrain\" : \"\",\"utilities\" : \"\",\"remark\" : \"\" }";
     }
     else
     {
         req.Message = existingHighlight.Message;
         req.Id = existingHighlight.Id;
     }
     dynamic jsonObj = JsonConvert.DeserializeObject(req.Message);
     jsonObj[viewModel.Property] = viewModel.Message;
     req.Message = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
     var resp = _highlightService.SaveHighlight(req);
     return Json(resp);
 }
Exemple #2
0
 public SaveHighlightResponse SaveHighlight(SaveHighlightRequest request)
 {
     try
     {
         var todayHighlight = DataContext.Highlights.FirstOrDefault(x => x.Date == request.Date && x.HighlightType.Id == request.TypeId);
         if (todayHighlight != null && todayHighlight.Id != request.Id)
         {
             return new SaveHighlightResponse
             {
                 IsSuccess = false,
                 Message = "You can only save one type of highlight in the same periode of time"
             };
         }
         if (request.Id == 0)
         {
             var highlight = request.MapTo<Highlight>();
             var selectOption = DataContext.SelectOptions.Single(x => x.Id == request.TypeId);
             var highlightType = selectOption;
             highlight.Type = selectOption.Value;
             DataContext.SelectOptions.Attach(highlightType);
             highlight.HighlightType = highlightType;
             DataContext.Highlights.Add(highlight);
         }
         else
         {
             var highlight = DataContext.Highlights.FirstOrDefault(x => x.Id == request.Id);
             if (highlight != null)
             {
                 request.MapPropertiesToInstance<Highlight>(highlight);
                 var selectOption = DataContext.SelectOptions.Single(x => x.Id == request.TypeId);
                 var highlightType = selectOption;
                 highlight.Type = selectOption.Value;
                 DataContext.SelectOptions.Attach(highlightType);
                 highlight.HighlightType = highlightType;
             }
         }
         DataContext.SaveChanges();
         return new SaveHighlightResponse
         {
             IsSuccess = true,
             Message = "Highlight has been saved"
         };
     }
     catch (InvalidOperationException e)
     {
         return new SaveHighlightResponse
         {
             IsSuccess = false,
             Message = e.Message
         };
     }
 }
 public ActionResult UpdateBrenfut(HighlightViewModel viewModel)
 {
     var existingHighlight = _highlightService.GetHighlightByPeriode(new GetHighlightRequest
     {
         Date = viewModel.Date,
         HighlightTypeId = viewModel.TypeId
     });
     SaveHighlightRequest req = new SaveHighlightRequest();
     req.PeriodeType = (PeriodeType)Enum.Parse(typeof(PeriodeType), viewModel.PeriodeType, true);
     req.Date = viewModel.Date.Value;
     req.TypeId = viewModel.TypeId;
     if (existingHighlight.Id == 0)
     {
         req.Message = "{\"a\" : { \"label\" : \"\", \"value\" : \"\" },\"b\" : { \"label\" : \"\", \"value\" : \"\" },\"c\" : { \"label\" : \"\", \"value\" : \"\" },\"d\" : { \"label\" : \"\", \"value\" : \"\" } }";
     }
     else
     {
         req.Message = existingHighlight.Message;
         req.Id = existingHighlight.Id;
     }
     dynamic jsonObj = JsonConvert.DeserializeObject(req.Message);
     jsonObj[viewModel.Property][viewModel.ValueType] = viewModel.Message;
     req.Message = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
     var resp = _highlightService.SaveHighlight(req);
     return Json(resp);
 }