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 IActionResult DeleteSignature(Guid SignatureId) { try { if (SignatureId == null || SignatureId == Guid.Empty) { _logger.LogError("Signature id null or empty"); return(BadRequest("Signature id is null or empty")); } var dbSignature = _signatureService.GetById(SignatureId); if (dbSignature.IsEmptyObject()) { _logger.LogError($"Signature with id: {SignatureId}, hasn't been found in db."); return(NotFound()); } _signatureService.Delete(dbSignature); return(NoContent()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside DeleteSignature action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public void Dispose() { //Delete created signature: var createdSignature = _signatureService.GetById(new Guid("e47c0cb5-05b6-437d-b40f-f2c5b5a08385")); if (createdSignature != null && createdSignature.Id != Guid.Empty) { _signatureService.Delete(createdSignature); } //Recovery modified signature: var modifiedSignature = _signatureService.GetById(new Guid("EED7F976-58B7-4C05-E3E4-08D6F9F0FC2C")); if (modifiedSignature != null && modifiedSignature.Id != Guid.Empty) { modifiedSignature.Name = "Signature 1"; _signatureService.Update(modifiedSignature); } }
public ActionResult DeleteSignature(int sigId) { _signatureService.Delete(sigId, commit: true); return(Ok()); }