public async Task DeleteEntity(EntityEntity Entity, string user, DateTime now) { var EntityEntity = await _context .EntityExpiration .Include(v => v.EntityMainPoint) .FirstOrDefaultAsync(v => v.EntityExpirationGuid == Entity.Id); if (EntityEntity?.EntityMainPoint == null) { throw new NotFoundException($"Entity for MainPoint {Entity.Id} does not found in db for deleting"); } if (EntityEntity.EntityMainPoint.RevokedByCorrelationId.HasValue) { throw new InvalidOperationException($"Cannot delete Entity on revocation process with requset {EntityEntity.EntityMainPoint.RevokedByRequestNumber}"); } EntityEntity.ValidTo = EntityEntity.ValidFrom.Value.AddDays(-1); EntityEntity.ModifiedBy = user; EntityEntity.ModifiedDate = now; EntityEntity.EntityMainPoint.ModifiedDate = now; EntityEntity.EntityMainPoint.ModifiedBy = user; await _context.SaveChangesAsync(); }
public async Task Update(EntityEntity EntityEntity, IPrincipal principal, DateTime now) { if (EntityEntity == null) { throw new ArgumentNullException(nameof(EntityEntity)); } if (EntityEntity.Id == Guid.Empty) { throw new ArgumentNullException(nameof(EntityEntity)); } var EntityMainPointEntity = await _context.EntityExpiration .Include(s => s.EntityMainPoint) .Include(s => s.EntityMainPoint.Lts) .Include(s => s.EntityMainPoint.Lts.Select(p => p.RnTaps)) .Where(s => s.EntityExpirationGuid == EntityEntity.Id) .Select(s => s.EntityMainPoint) .FirstOrDefaultAsync(); if (EntityMainPointEntity == null) { throw new NotFoundException($"Валидатор ({EntityEntity.Id}) не найден для обновления"); } UpdateEntityMainPointEntity(EntityEntity, EntityMainPointEntity, principal, now); await _context.SaveChangesAsync(); }
public async Task Send(EntityEntity EntityEntity) { if (EntityEntity?.RnGroup == null) { throw new InvalidOperationException("Cannot send Rn revokation email on non-Rn Entity"); } var Rn = EntityEntity.RnGroup; var model = new AnnulLastRnTerminalNotificationModel(Rn.Agn, EntityEntity.EntitySales.Address, EntityEntity.EntitySales.Deal.Name, EntityEntity.Number); var jsModel = JsonConvert.SerializeObject(model); var notificationConfig = _configuration.GetFor("AnnulLastRnTerminalNotification"); var command = new SendEmailMessageWithTemplateCommand { TemplateName = notificationConfig.Template.Name, Messages = new[] { new TemplateMessage { From = notificationConfig.From, Subject = notificationConfig.Subject, JsonModel = jsModel, To = notificationConfig.To, Cc = notificationConfig.CopyTo } } }; await _messageSender.Send(command, MailEndpointAddress); }
public static void EntityAreEqual(Entity Entity, EntityEntity EntityEntity, BasePoint BasePoint, Ep Ep) { Assert.Equal(Entity.EntityExpirations.First().EntityExpirationGuid, EntityEntity.Id); Assert.Equal(Entity.Number, EntityEntity.Number); Assert.Equal(Entity.EntityExpirations.First().ValidFrom, EntityEntity.ValidFrom); Assert.Equal(Entity.EntityExpirations.First().ValidTo, EntityEntity.ValidTo); Assert.Equal(BasePoint.Systematic.ToEntitySystematic(), EntityEntity.Systematic); var Place = EntityEntity.EntityPlaces.First(); EtDirectPlaceAreEqual(Place, Ep); }
public async Task Create(EntityEntity newEntity, IPrincipal principal, DateTime now) { if (newEntity == null) { throw new ArgumentNullException(nameof(newEntity)); } if (newEntity.EntitySales == null || newEntity.EntitySales.Id == Guid.Empty) { throw new ArgumentNullException(nameof(newEntity.EntitySales)); } if (principal?.Identity == null) { throw new ArgumentNullException(nameof(principal)); } var MainPoint = await _context.EusMainPoint.FirstOrDefaultAsync(s => s.Id == newEntity.EntitySales.Id); if (MainPoint == null) { throw new NotFoundException($"MainPoint ({newEntity.EntitySales.Id}) не найден для создания валидатора"); } var dbEntityNumber = await _context.Entity.FirstOrDefaultAsync(v => v.Number == newEntity.Number); if (dbEntityNumber == null) { throw new NotFoundException($"Entity с номером ({newEntity.Number}) не найден"); } var MainPointType = _context.MainPointType.FirstOrDefault(st => st.Name == EntitySales._Test_MainPoint_Type); var EntityMainPointEntity = CreateEntityMainPoint(newEntity.Id, newEntity.Sys.ToSys(), MainPoint, newEntity.IsTest, now, principal.Identity.Name, dbEntityNumber.EntityGuid, MainPointType); UpdateEntityMainPointEntity(newEntity, EntityMainPointEntity, principal, now); _context.MainPoint.Add(EntityMainPointEntity); await _context.SaveChangesAsync(); }
public async Task Send(EntityEntity Entity, string user) { if (Entity?.RnGroup == null) { throw new InvalidOperationException("Cannot send Rn revokation email on non-Rn Entity"); } var Rn = Entity.RnGroup; var command = new RemoveRnMainPointFromGRPCommand { AgencyCode = Entity.EntitySales.Agent.Code, Author = user, MainPointRnGroupCode = Rn.Grp, MainPointEntity = Entity.Number, TKPCode = Rn.Agn }; await _ProcessMessageSender.Send(command, Endpoint); }
public async Task CreateNewEntity(CreateEntityEntityCommandDto cmd, IPrincipal principal) { _createValidation.ValidateAndThrow(cmd); var now = _dateTimeProvider.GetLocalNow(); var EntitySales = await _EntitySalesRepository.GetById(cmd.UesEntitySaleId); if (EntitySales == null) { throw new NotFoundException($"EntitySales({cmd.UesEntitySaleId}) не найден"); } var EntityEntity = new EntityEntity(EntitySales, new EntityNumber(cmd.EntityNumber), cmd.Systematic.GetValueOrDefault().ToEntitySystematic(), now.Date, isTest: cmd.IsTest); UpdateEntity(cmd, principal, EntityEntity); await _repo.Create(EntityEntity, principal, now); }
public EntitySalesRepositoryTests() { _scope = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled); _container = CompositionRoot.GetContainer(); _EntityEp = new Ep { EpGuid = Guid.NewGuid(), ValidFrom = _targetSqlDate, ValidTo = _targetSqlDate, PlaceId = PlaceId, EpSystem = string.Empty, OFFC = string.Empty, AutorizeDate = _targetSqlDate, AK = string.Empty, Comment = string.Empty, CreatedDate = _minSqlDate, ModifiedDate = _minSqlDate }; _EntityEp = new Ep { EpGuid = Guid.NewGuid(), ValidFrom = _targetSqlDate, ValidTo = _targetSqlDate, PlaceId = PlaceId, EpSystem = string.Empty, OFFC = string.Empty, AutorizeDate = _targetSqlDate, AK = string.Empty, Comment = string.Empty, CreatedDate = _minSqlDate, ModifiedDate = _minSqlDate }; _EntityEp = new Ep { EpGuid = Guid.NewGuid(), ValidFrom = _targetSqlDate, ValidTo = _targetSqlDate, PlaceId = PlaceId, EpSystem = string.Empty, OFFC = string.Empty, AutorizeDate = _targetSqlDate, AK = string.Empty, Comment = string.Empty, CreatedDate = _minSqlDate, ModifiedDate = _minSqlDate }; _EntityEntityalePoint = new BasePoint { BasePointGuid = FakeBasePointId, Deal = new Deal { Code = AgencyCode }, TownCode = "OVB", Address = string.Empty, BasePointTypeGuid = Guid.Parse("18D2C60A-9718-4ED0-BA31-8E563A17FF4A"), CreatedDate = _minSqlDate, ModifiedDate = _minSqlDate, Systematic = SystematicType.UesET, Eps = new[] { _EntityEp } }; _UesEtBasePoint = new BasePoint { BasePointGuid = FakeBasePointId, Deal = new Deal { Code = AgencyCode }, TownCode = "OVB", Address = string.Empty, BasePointTypeGuid = Guid.Parse("18D2C60A-9718-4ED0-BA31-8E563A17FF4A"), CreatedDate = _minSqlDate, ModifiedDate = _minSqlDate, Systematic = SystematicType.UesET, Eps = new[] { _EntityEp } }; _UesBasePoint = new UesBasePoint { Id = Guid.NewGuid(), BasePointId = BasePointId, DealCode = AgencyCode, ValidFrom = _targetSqlDate, ValidTo = _targetSqlDate, CreatedDate = _minSqlDate, ModifiedDate = _minSqlDate, TownCode = "MOW", Address = string.Empty, SaleType = 0, Organization = new Organization { Code = AgencyCode, Role = "~", CreatedDate = _minSqlDate, ModifiedDate = _minSqlDate }, EntityBasePoints = new[] { _UesEtBasePoint } }; _firstEntity = new Entity { EntityGuid = Guid.NewGuid(), Number = FirstEntityNumber, EntityExpirations = new[] { new EntityExpiration { EntityExpirationGuid = Guid.NewGuid(), BasePointGuid = _UesEtBasePoint.BasePointGuid, IsActive = true, ValidFrom = _targetSqlDate, ValidTo = _targetSqlDate, ModifiedDate = _minSqlDate } } }; _secondEntity = new Entity { EntityGuid = Guid.NewGuid(), Number = SecondEntityNumber, EntityExpirations = new[] { new EntityExpiration { EntityExpirationGuid = Guid.NewGuid(), BasePointGuid = _UesEtBasePoint.BasePointGuid, IsActive = true, ValidFrom = _targetSqlDate, ValidTo = _targetSqlDate, ModifiedDate = _minSqlDate } } }; _notActiveEntity = new Entity { EntityGuid = Guid.NewGuid(), Number = NonActiveEntityNumber, EntityExpirations = new[] { new EntityExpiration { EntityExpirationGuid = Guid.NewGuid(), BasePointGuid = _UesEtBasePoint.BasePointGuid, IsActive = false, ValidFrom = _targetSqlDate, ValidTo = _targetSqlDate, ModifiedDate = _minSqlDate } } }; _expiredEntity = new Entity { EntityGuid = Guid.NewGuid(), Number = NonActiveEntityNumber, EntityExpirations = new[] { new EntityExpiration { EntityExpirationGuid = Guid.NewGuid(), BasePointGuid = _UesEtBasePoint.BasePointGuid, IsActive = true, ValidFrom = _minSqlDate, ValidTo = _minSqlDate, ModifiedDate = _minSqlDate } } }; _futureEntity = new Entity { EntityGuid = Guid.NewGuid(), Number = NonActiveEntityNumber, EntityExpirations = new[] { new EntityExpiration { EntityExpirationGuid = Guid.NewGuid(), BasePointGuid = _UesEtBasePoint.BasePointGuid, IsActive = false, ValidFrom = _targetSqlDate.AddDays(1), ValidTo = _targetSqlDate.AddDays(1), ModifiedDate = _minSqlDate } } }; _newEntityEntity = new EntityEntity(new EntityEntityDataAccessModel { Number = NewEntityEntityNumber, SystematicType = EntitySystematicType.ElioET, ValidFrom = DateTime.Now, ValidTo = DateTime.Now.AddDays(1), Places = new List <EntityPlaceDataAccessModel> { { new EntityPlaceDataAccessModel { Pcc = "~~~~1", AuthorizationDate = DateTime.Now } } } }); _newSabreEtEntity = new EntityEntity(new EntityEntityDataAccessModel { Number = NewEntityEntityNumber, SystematicType = EntitySystematicType.SabreET, ValidFrom = DateTime.Now, ValidTo = DateTime.Now.AddDays(1), Places = new List <EntityPlaceDataAccessModel> { { new EntityPlaceDataAccessModel { Pcc = "AZ12", AuthorizationDate = DateTime.Now, } } } }); _newSrnEntity = new EntityEntity(new EntityEntityDataAccessModel { Number = NewEntityEntityNumber, SystematicType = EntitySystematicType.Srn, ValidFrom = DateTime.Now, ValidTo = DateTime.Now.AddDays(1), SrnEntity = new SrnEntityDataAccessModel { Agn = "12Ааа", Grp = "4211111111", SrnPools = new List <SrnPoolDataAccessModel> { new SrnPoolDataAccessModel { PoolNumber = "Аааа12", AuthorizationDate = DateTime.Now } } } }); CreateEntityForTestInDatabase(); }
private static void UpdateEntity(IEntityEntityDto cmd, IPrincipal principal, EntityEntity EntityEntity) { EntityEntity.Comment = cmd.Comment; EntityEntity.SetLocation(cmd.Location.ToDomainType(), cmd.SiteAudience.ToDomainType()); switch (EntityEntity.Systematic) { case EntitySystematicType.UesET: case EntitySystematicType.ElioET: case EntitySystematicType.SabreET: { if (cmd.EntityPlaces == null || !cmd.EntityPlaces.Any()) { if (EntityEntity.EntityPlaces.Any()) { throw new InvalidOperationException($"Нельзя удалить все офисы на валидаторе"); } else { break; } } var EntityPlaces = EntityEntity.EntityPlaces.ToDictionary(x => x.Id); foreach (var Place in cmd.EntityPlaces) { if (Place.Id.HasValue && EntityPlaces.TryGetValue(Place.Id.Value, out var existed)) { existed.Pcc = Place.Pcc; existed.AuthorizationDate = Place.AuthorizationDate; EntityPlaces.Remove(Place.Id.Value); } else { EntityEntity.AddPlace(new EntityPlace(Place.Pcc, Place.AuthorizationDate)); } } foreach (var Place in EntityPlaces.Values) { EntityEntity.RemovePlace(Place); } break; } case EntitySystematicType.Srn: { if (cmd.SrnEntity == null) { if (EntityEntity.SrnGroup != null) { throw new InvalidOperationException($"Нельзя удалить информацию о подключении к СБ Сирена на валидаторе"); } else { break; } } if (cmd.SrnEntity.SrnPools == null || !cmd.SrnEntity.SrnPools.Any()) { throw new InvalidOperationException("Cannot create Srn Entity without taps"); } if (EntityEntity.SrnGroup == null) { var val = new SrnGroup(cmd.SrnEntity.Agn, cmd.SrnEntity.Grp); EntityEntity.SetSrnGroup(val); foreach (var item in cmd.SrnEntity.SrnPools.Select(x => new SrnPool(x.PoolNumber, x.AuthorizationDate))) { EntityEntity.AddTap(item); } } else { var val = new SrnGroup(cmd.SrnEntity.Agn, cmd.SrnEntity.Grp); if (EntityEntity.SrnGroup != val) { if (principal.IsAdmin()) { EntityEntity.SetSrnGroup(val); } else { throw new InvalidOperationException("Нельзя обновить информацию о подключении к СБ Сирена на валидаторе"); } } var EntityTaps = EntityEntity.SrnPools.ToDictionary(x => x.Id); foreach (var tap in cmd.SrnEntity.SrnPools) { if (tap.Id.HasValue && EntityTaps.TryGetValue(tap.Id.Value, out var existed)) { existed.Tap = tap.PoolNumber; existed.AuthorizationDate = tap.AuthorizationDate; EntityTaps.Remove(tap.Id.Value); } else { EntityEntity.AddTap(new SrnPool(tap.PoolNumber, tap.AuthorizationDate)); } } foreach (var tap in EntityTaps.Values) { EntityEntity.RemoveTap(tap); } } break; } case EntitySystematicType.Unknown: if (IsRg(EntityEntity.EntitySales.Deal)) { break; } else { goto default; } default: throw new InvalidOperationException("Невозможно создать валидатор без системы бронирования"); } }
private void UpdateEntityMainPointEntity(EntityEntity EntityEntity, MainPoint EntityMainPointEntity, IPrincipal principal, DateTime now) { switch (EntityEntity.Sys) { case EntitySysType.EusET: case EntitySysType.ElioET: case EntitySysType.SabreET: { var LtSystem = EntityMainPointEntity.Sys.ToLtSystem(); var PlacesInDb = EntityMainPointEntity.Lts.Where(x => x.LtSystem == LtSystem).ToDictionary(x => x.LtGuid); var PlacesInModel = EntityEntity.EntityPlaces ?? Array.Empty <EntityPlace>(); if (PlacesInDb.Any() && !PlacesInModel.Any()) { throw new InvalidOperationException($"Нельзя удалить все офисы на валидаторе ({EntityEntity.Id})"); } if (PlacesInModel.Any()) { EntityMainPointEntity.AuthorizationDate = PlacesInModel.Min(x => x.AuthorizationDate); } foreach (var Place in PlacesInModel) { if (PlacesInDb.TryGetValue(Place.Id, out var existed)) { UpdateFromPlace(existed, Place); PlacesInDb.Remove(Place.Id); } else { var newLt = CreateLt(Place.Id, EntityEntity.EntitySales.Agent.Code, EntityMainPointEntity.MainPointGuid, LtSystem, principal.Identity.Name, now); UpdateFromPlace(newLt, Place); EntityMainPointEntity.Lts.Add(newLt); } } if (PlacesInDb.Any()) { _context.Lt.RemoveRange(PlacesInDb.Values); } break; } case EntitySysType.Rn: { var Rn = EntityMainPointEntity.Lts.Where(x => x.LtSystem == LtSystems.Rn && x.RnStatus && x.RnTaps.Any()) .GroupBy(x => new { x.AGN, x.GRP }).SingleOrDefault(); if (EntityEntity.RnGroup == null && Rn == null) { break; } if (EntityEntity.RnGroup == null && Rn != null) { throw new NotFoundException($"Rn терминал у пункта продаж ({EntityEntity.Id}) не найден для обновления"); } if (!principal.IsAdmin() && Rn != null) { if (EntityEntity.RnGroup.Agn != Rn.Key.AGN || EntityEntity.RnGroup.Grp != Rn.Key.GRP) { throw new InvalidOperationException($"Нельзя изменить ТКП и ГРП на авторизованном валидаторе ({EntityEntity.Id})"); } } var tapsInDb = Rn?.ToDictionary(x => x.LtGuid) ?? new Dictionary <Guid, Lt>(); var tapsInModel = EntityEntity.RnTerminals ?? Array.Empty <RnTerminal>(); if (tapsInDb.Any() && !tapsInModel.Any()) { throw new InvalidOperationException($"Нельзя удалить все ТАП на валидаторе ({EntityEntity.Id})"); } if (tapsInModel.Any()) { EntityMainPointEntity.AuthorizationDate = tapsInModel.Min(x => x.AuthorizationDate); } foreach (var tap in tapsInModel) { if (tapsInDb.TryGetValue(tap.Id, out var existed)) { UpdateFromTap(existed, EntityEntity.RnGroup, tap); tapsInDb.Remove(tap.Id); } else { var newLt = CreateLt(tap.Id, EntityEntity.EntitySales.Agent.Code, EntityMainPointEntity.MainPointGuid, LtSystems.Rn, principal.Identity.Name, now); UpdateFromTap(newLt, EntityEntity.RnGroup, tap); EntityMainPointEntity.Lts.Add(newLt); } } if (tapsInDb.Any()) { foreach (var Lt in tapsInDb.Values) { Lt.ReleaseDate = now; Lt.RnStatus = false; } } break; } case EntitySysType.Unknown when EntityMainPointEntity.AgentCode == "1488": break; default: throw new DomainException($"Reservation system for Entity ({EntityMainPointEntity.MainPointGuid}) is not recognized"); } #warning добавить изменение Location при аптейте связанной EusMainPoint в ETR.Test.Eus.BusinessLogic.MainPoint.UpdateMainPointHandler EntityMainPointEntity.Location = (EntityPlaceLocationTypes)EntityEntity.Location; EntityMainPointEntity.IsOnline = EntityEntity.Location == LocationTypes.Online; EntityMainPointEntity.Rto = EntityEntity.Location == LocationTypes.Rto; EntityMainPointEntity.SiteAudience = (EntityPlaceSiteAudienceTypes)EntityEntity.SiteAudience; EntityMainPointEntity.Comment = EntityEntity.Comment; //можно указывать только при создании //MainPoint.IsTest = cmd.IsTest; EntityMainPointEntity.ModifiedBy = principal.Identity.Name; EntityMainPointEntity.ModifiedDate = now; }
public Task Update(EntityEntity Entity, IPrincipal principal, DateTime now) => Task.CompletedTask;
public Task DeleteEntity(EntityEntity Entity, string user, DateTime now) => Task.CompletedTask;
public Task Create(EntityEntity EntitySales, IPrincipal user, DateTime now) => Task.CompletedTask;
public MapPlaceEntityEntityExpiration(EntityPlace Place, EntityEntity Entity, EntityExpiration EntityExpiration) { Place = Place; Entity = Entity; EntityExpiration = EntityExpiration; }