Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public ActionResult InsertSignature(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 newSig = new Signature
            {
                SignatureId   = dto.SignatureId.ToUpper(),
                ExpiryDate    = dto.ExpiryDate,
                Name          = dto.Name,
                SignatureType = dto.SignatureType,
                MaskId        = maskId,
                SystemId      = dto.SystemId
            };

            _signatureService.Insert(newSig, commit: true);
            _signatureService.WormholeSigUpdate(dto, newSig, maskId);
            return(Ok());
        }