public SolarSystemDto UpdateSolarSystemSignatures(string mainToken, SolarSystemDto dto) { var main = _characterService.GetMainCharacterByToken(mainToken); var maskId = main.MaskType == MaskType.Alliance && main.Pilot.Corporation.AllianceId != null ? main.Pilot.Corporation.Alliance.MaskId : main.Pilot.Corporation.MaskId; var system = _solarSystemService.GetSystemById(dto.Id); var dtoSigIds = dto.Signatures.Select(x => x.Id).ToHashSet(); var systemSigIds = system.Signatures.Where(x => x.MaskId == maskId).Select(x => x.Id).ToHashSet(); //to delete foreach (var toDeleteId in systemSigIds.Where(x => !dtoSigIds.Contains(x)).ToList()) { var toDelete = _signatureService.GetBySignatureId(toDeleteId); if (toDelete.DestinationId != null) { var destoSig = _signatureService.GetBySignatureId(toDelete.DestinationId.Value); destoSig.DestinationId = null; toDelete.DestinationId = null; _signatureService.Update(destoSig); _signatureService.Update(toDelete, commit: true); _signatureService.Delete(destoSig.Id); } _signatureService.Delete(toDelete.Id, commit: true); } //to update or add foreach (var updateSig in dto.Signatures) { var systemSig = _signatureService.GetBySignatureId(updateSig.Id); if (systemSig == null) { //create new sig systemSig = new Signature { SignatureId = updateSig.SignatureId, ExpiryDate = updateSig.ExpiryDate, Name = updateSig.Name, SignatureType = updateSig.SignatureType, MaskId = maskId, SystemId = dto.Id }; system.Signatures.Add(systemSig); } else { systemSig.SignatureId = updateSig.SignatureId; systemSig.ExpiryDate = updateSig.ExpiryDate; systemSig.Name = updateSig.Name; systemSig.SignatureType = updateSig.SignatureType; } _solarSystemService.UpdateSystem(system); _signatureService.WormholeSigUpdate(updateSig, systemSig, maskId); } _solarSystemService.UpdateSystem(system); return(GetSolarSystemById(mainToken, dto.Id)); }
public ActionResult UpdateSignature(string mainToken, SignatureDto dto) { var main = _characterService.GetMainCharacterByToken(mainToken); var maskId = main.MaskType == MaskType.Alliance && main.Pilot.Corporation.AllianceId != null ? main.Pilot.Corporation.Alliance.MaskId : main.Pilot.Corporation.MaskId; var sig = _signatureService.GetBySignatureId(dto.Id); sig.SignatureId = dto.SignatureId; //sig.ExpiryDate = dto.ExpiryDate; sig.Name = dto.Name; sig.SignatureType = dto.SignatureType; _signatureService.WormholeSigUpdate(dto, sig, maskId); return(Ok()); }