예제 #1
0
 public ActionResult Edit(RelayDataDTO relayDataDTO)
 {
     if (Request.IsAuthenticated)
     {
         _relayDataService.SaveOrUpdate(relayDataDTO);
         return RedirectToAction("Details", "ControlObject", new { id = _relayDataService.GetControlObjectIdByRelayDataId(relayDataDTO.Id) });
     }
     return RedirectToAction("AccessIsClosed", "Exception");
 }
예제 #2
0
 public ActionResult Create(RelayDataDTO relayDataDTO)
 {
     if (Request.IsAuthenticated)
     {
         relayDataDTO.Id = 0;
         _relayDataService.SaveOrUpdate(relayDataDTO);
         return RedirectToAction("Details", "ControlObject", new { id = relayDataDTO.ControlObject.Id });
     }
     return RedirectToAction("AccessIsClosed", "Exception");
 }
예제 #3
0
        public int SaveOrUpdate(RelayDataDTO relayDataDTO)
        {
            var relayData = relayDataDTO.Id == 0 ? new RelayData() : _relayDataRepository.Get(relayDataDTO.Id);

            relayData.Id = relayDataDTO.Id;
            var isChangeVal = relayDataDTO.Id == 0 || relayDataDTO.Value != relayData.Value;
            if (isChangeVal)
                relayData.LastUpdate = DateTime.Now;
            if (!string.IsNullOrEmpty(relayDataDTO.Name))
                relayData.Name = relayDataDTO.Name;
            if (relayDataDTO.PinName != 0)
                relayData.PinName = relayDataDTO.PinName;
            relayData.Value = relayDataDTO.Value;
            if (relayDataDTO.ControlObject != null)
                relayData.ControlObject = new ControlObject { Id = relayDataDTO.ControlObject.Id };

            var id = _relayDataRepository.SaveOrUpdate(relayData);

            if (isChangeVal)
                _actionLogService.SetActionLog(string.Format("{0} {1} '{2}'",relayDataDTO.Id > 0 ? (relayData.Value ? "включил(а)" : "отключил(а)") : "", relayDataDTO.Id > 0 ? "исполнительную систему" : "создал(а) исполнительную систему", relayData.Name), id, typeof(RelayData).Name);

            return id;
        }