public IActionResult UpdateTarget([FromBody] Target aObject) { if (aObject == null) { return(BadRequest()); } TarRepo.Update(aObject); return(Ok(aObject)); }
public async Task <CommandResult <TargetDto> > Handle(Command message, CancellationToken cancellationToken) { if (message.Target.CreateSelfSignedCertificate) { return(await ReCreateCertificate(message.Target.Id)); } var theTargetWithDomain = await _repository.GetTargetWithTheDomain(message.Target.Domain); var target = await _repository.GetById(message.Target.Id); if (target == null || (theTargetWithDomain != null && theTargetWithDomain.Id != target.Id)) { return(new CommandResult <TargetDto>() { IsSucceeded = false }); } target.OriginIpAddress = message.Target.OriginIpAddress; target.UseHttps = message.Target.UseHttps; target.CertCrt = message.Target.CertCrt; target.CertKey = message.Target.CertKey; target.WAFEnabled = message.Target.WAFEnabled; target.AutoCert = message.Target.AutoCert; if (target.Domain != message.Target.Domain) { var ssl = SSLHelper.CreateSSL(message.Target.Domain); target.Domain = message.Target.Domain; } await _repository.Update(target); return(new CommandResult <TargetDto>() { IsSucceeded = true, Result = _mapper.Map <TargetDto>(target) }); }
//[Authorize(Roles = "Координатор ПСР")] public ActionResult <Target> UpdateTarget(int id, TargetUpdateDto targetUpdateDto) { var target = _targetRepository.GetById(id); if (target == null) { return(NotFound()); } _mapper.Map(targetUpdateDto, target); _targetRepository.Update(target); //Best practice _targetRepository.SaveChanges(); _notificationHub.Clients.All.SendAsync("SendMessage", "TargetUpdated"); _notificationHub.Clients.All.SendAsync("Notification", "Цель " + target.Title + " обновлена."); return(NoContent()); }
public MetaEntitySyncResult SyncEntityToTarget(IList <MetaEntity> queriedEntities) { try { // 根据原实体 Id 集合,查找已存在的 Target IList <string> originalIds = queriedEntities.Select(t => t.OriginalId).ToList(); IList <Target> existTargets = targetManager.GetTargetsByIds(originalIds); // 筛选出需要更新以及插入的 Target IList <Target> targetsToUpdate = new List <Target>(); IList <Target> targetsToInsert = new List <Target>(); foreach (MetaEntity queriedEntity in queriedEntities) { Target existTarget = existTargets.SingleOrDefault(et => et.Type == queriedEntity.Type && et.OriginalId == queriedEntity.OriginalId); // 未找到对应 Target if (existTarget == null) { Target targetToAdd = new Target { Type = queriedEntity.Type, OriginalId = queriedEntity.OriginalId, Name = queriedEntity.Name, }; targetsToInsert.Add(targetToAdd); ++InsertedTargetCount; continue; } // 找到记录,但未更改 if (existTarget.Name == queriedEntity.Name) { continue; } // 找到记录,并且记录被更改 existTarget.Name = queriedEntity.Name; targetsToUpdate.Add(existTarget); ++UpdatedTargetCount; } // 更新与插入 foreach (Target targetToUpdate in targetsToUpdate) { targetRepository.Update(targetToUpdate); } foreach (Target targetToInsert in targetsToInsert) { targetRepository.Insert(targetToInsert); } // 获取更新并插入过后的 Target IList <Target> syncedTargets = targetManager.GetTargetsByIds(originalIds); return(new MetaEntitySyncResult { Targets = syncedTargets, InsertedCount = targetsToInsert.Count, UpdatedCount = targetsToUpdate.Count, UnchangedCount = queriedEntities.Count - targetsToInsert.Count - targetsToUpdate.Count }); } catch (Exception ex) { Logger.Error(ex.Message); throw new ApplicationException("同步Entity至Target失败", ex); } }
public Target Update(Target item) { Repo.Update(item); Unit.SaveChanges(); return(item); }