예제 #1
0
        public async Task Handle(CompanyNameChangedEvent message)
        {
            using (var context = new RegistryDbContext())
            {
                var company = (from c in context.Parties.OfType <Company>()
                               where c.OriginalId == message.CompanyId
                               select c).Single();
                company.DisplayName = message.CompanyName;
                company.CompanyName = message.CompanyName;

                await context.SaveChangesAsync();
            }
        }
예제 #2
0
        public async Task <Response <UpdateResult> > Handle(ChangeTagName request)
        {
            var tag = await _context.Tags.FirstOrDefaultAsync(x => x.Name.Equals(request.TagName));

            if (tag == null)
            {
                return(new Response <UpdateResult>(UpdateResult.NotFound));
            }

            tag.Name = request.NewTagName;
            await _context.SaveChangesAsync();

            return(new Response <UpdateResult>(UpdateResult.Updated));
        }
예제 #3
0
        public async Task Handle(CompanyMainContactAssociatedEvent message)
        {
            using (var context = new RegistryDbContext(Options))
            {
                var company = (from c in context.Companies
                               where c.OriginalId == message.CompanyId
                               select c).Single();
                var person = (from c in context.People
                              where c.OriginalId == message.MainContactId
                              select c).Single();
                company.MainContact = $"{person.FirstName} {person.LastName}";

                await context.SaveChangesAsync();
            }
        }
예제 #4
0
        public async Task Handle(CompanyMainContactAssociatedEvent message)
        {
            using (var context = new RegistryDbContext())
            {
                var company = (from c in context.Parties.OfType <Company>()
                               where c.OriginalId == message.CompanyId
                               select c).Single();
                var person = (from c in context.Parties.OfType <Person>()
                              where c.OriginalId == message.MainContactId
                              select c).Single();
                company.MainContact = person;

                await context.SaveChangesAsync();
            }
        }
예제 #5
0
        private async Task <Response <DeleteResult> > DeleteTagsOfApiAsync(DeleteTag request)
        {
            var api = await _context.Apis.FirstOrDefaultAsync(x => x.Name.Equals(request.ApiName));

            if (api == null)
            {
                return(new Response <DeleteResult>(DeleteResult.NotFound, "No API with the supplied nbame could be found"));
            }

            var apiTags = _context.ApiTags.AsQueryable();

            if (!string.IsNullOrEmpty(request.TagName))
            {
                apiTags = apiTags.Where(x => x.Tag.Name.Equals(request.TagName));
            }

            var apiTagsToDelete = await apiTags.ToListAsync();

            _context.ApiTags.RemoveRange(apiTagsToDelete);

            await _context.SaveChangesAsync();

            return(new Response <DeleteResult>(DeleteResult.Deleted));
        }
예제 #6
0
        public async Task Handle(CompanyRegisteredEvent message)
        {
            var p = new Company()
            {
                CompanyName = message.CompanyName,
                VatIndex    = message.VatIndex,
                OriginalId  = message.CompanyId,
                DisplayName = message.CompanyName
            };

            using (var context = new RegistryDbContext())
            {
                context.Parties.Add(p);
                await context.SaveChangesAsync();
            }
        }
예제 #7
0
        public async Task <Response <DeleteResult> > Handle(DeleteApi request)
        {
            var api = await _context.Apis.FirstOrDefaultAsync(x => x.Name.Equals(request.ApiName));

            if (api == null)
            {
                return(new Response <DeleteResult>(DeleteResult.NotFound));
            }

            await DeleteTagsOfApiAsync(api);

            _context.Apis.Remove(api);
            await _context.SaveChangesAsync();

            return(new Response <DeleteResult>(DeleteResult.Deleted));
        }
예제 #8
0
        public async Task Handle(PersonRegisteredEvent message)
        {
            var p = new Person()
            {
                FirstName   = message.FirstName,
                LastName    = message.LastName,
                OriginalId  = message.PersonId,
                DisplayName = $"{message.FirstName} {message.LastName}"
            };

            using (var context = new RegistryDbContext())
            {
                context.Parties.Add(p);
                await context.SaveChangesAsync();
            }
        }
예제 #9
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Page());
            }

            var newCategory = new Category {
                Name    = this.Input.Name,
                Comment = this.Input.Comment
            };

            _dc.Categories.Add(newCategory);
            await _dc.SaveChangesAsync();

            return(this.RedirectToPage("Index"));
        }
예제 #10
0
        public async Task <Response <CreateResult> > Handle(CreateApi request)
        {
            await AddApiAsync(request);

            var tagsResponse = await SetApiTagsAsync(request);

            if (tagsResponse.Result == UpdateResult.Updated)
            {
                await _context.SaveChangesAsync();

                return(new Response <CreateResult>(CreateResult.Created));
            }
            else
            {
                return(new Response <CreateResult>(CreateResult.NotCreated,
                                                   $"Create aborted - could not add tags. Message is {tagsResponse.Description}"));
            }
        }
예제 #11
0
        public async Task <Response <DeleteResult> > Handle(DeleteApiVersion request)
        {
            var apiVersion = await _context.ApiVersions
                             .Include(x => x.Api)
                             .SingleOrDefaultAsync(x => x.Api.Name.Equals(request.ApiName) &&
                                                   x.MajorVersion == request.MajorVersion &&
                                                   x.MinorVersion == request.MinorVersion);

            if (apiVersion == null)
            {
                return(new Response <DeleteResult>(DeleteResult.NotFound));
            }

            _context.ApiVersions.Remove(apiVersion);
            await _context.SaveChangesAsync();

            return(new Response <DeleteResult>(DeleteResult.Deleted));
        }
예제 #12
0
        public async Task Handle(PartyLegalAddressChangedEvent message)
        {
            using (var context = new RegistryDbContext(Options))
            {
                var legalAddress = new PostalAddress()
                {
                    Address    = message.Address,
                    City       = message.City,
                    Country    = message.Country,
                    PostalCode = message.PostalCode,
                    Province   = message.Province
                };
                var party = (from c in context.Parties
                             where c.OriginalId == message.PartyId
                             select c).Single();
                party.LegalAddress = legalAddress;

                await context.SaveChangesAsync();
            }
        }
예제 #13
0
        public async Task Handle(CompanyRegisteredEvent message)
        {
            var p = new Company()
            {
                DisplayName = message.CompanyName,
                CompanyName = message.CompanyName,
                VatIndex    = message.VatIndex,
                OriginalId  = message.CompanyId,
                NationalIdentificationNumber = message.NationalIdentificationNumber ?? string.Empty,
                LegalAddress = new PostalAddress
                {
                    Address    = message.LegalAddressAddress,
                    City       = message.LegalAddressCity,
                    Country    = message.LegalAddressCountry,
                    PostalCode = message.LegalAddressPostalCode,
                    Province   = message.LegalAddressProvince
                },
                ShippingAddress = new PostalAddress()
                {
                    Address    = message.ShippingAddressAddress,
                    City       = message.ShippingAddressCity,
                    Country    = message.ShippingAddressCountry,
                    PostalCode = message.ShippingAddressPostalCode,
                    Province   = message.ShippingAddressProvince
                },
                BillingAddress = new PostalAddress()
                {
                    Address    = message.BillingAddressAddress,
                    City       = message.BillingAddressCity,
                    Country    = message.BillingAddressCountry,
                    PostalCode = message.BillingAddressPostalCode,
                    Province   = message.BillingAddressProvince
                }
            };

            using (var context = new RegistryDbContext(Options))
            {
                context.Companies.Add(p);
                await context.SaveChangesAsync();
            }
        }
예제 #14
0
        public async Task Handle(ContactInfoSetForPartyEvent message)
        {
            using (var context = new RegistryDbContext())
            {
                var contactInfo = new ContactInfo()
                {
                    PhoneNumber      = message.PhoneNumber,
                    MobileNumber     = message.MobileNumber,
                    FaxNumber        = message.FaxNumber,
                    WebsiteAddress   = message.WebsiteAddress,
                    EmailAddress     = message.EmailAddress,
                    InstantMessaging = message.InstantMessaging
                };
                var party = (from c in context.Parties
                             where c.OriginalId == message.PartyId
                             select c).Single();
                party.ContactInfo = contactInfo;

                await context.SaveChangesAsync();
            }
        }
예제 #15
0
        public async Task Handle(CompanyRegisteredEvent message)
        {
            var p = new Company()
            {
                CompanyName = message.CompanyName,
                VatIndex    = message.VatIndex,
                OriginalId  = message.CompanyId,
                DisplayName = message.CompanyName,
                NationalIdentificationNumber = message.NationalIdentificationNumber ?? "",
                ShippingAddress = new PostalAddress(),
                LegalAddress    = new PostalAddress(),
                BillingAddress  = new PostalAddress(),
                ContactInfo     = new ContactInfo()
            };

            using (var context = new RegistryDbContext())
            {
                context.Parties.Add(p);
                await context.SaveChangesAsync();
            }
        }
예제 #16
0
        public async Task Handle(PersonRegisteredEvent message)
        {
            var p = new Person()
            {
                FirstName   = message.FirstName,
                LastName    = message.LastName,
                OriginalId  = message.PersonId,
                DisplayName = $"{message.FirstName} {message.LastName}",
                NationalIdentificationNumber = message.NationalIdentificationNumber,
                VatIndex        = message.VatNumber,
                BillingAddress  = new PostalAddress(),
                LegalAddress    = new PostalAddress(),
                ShippingAddress = new PostalAddress(),
                ContactInfo     = new ContactInfo()
            };

            using (var context = new RegistryDbContext())
            {
                context.Parties.Add(p);
                await context.SaveChangesAsync();
            }
        }
예제 #17
0
        public async Task <Response <DeleteResult> > Handle(DeleteDomain request)
        {
            var domain = await _context.BusinessDomains
                         .Include(x => x.SubDomains)
                         .FirstOrDefaultAsync(x => x.Name.Equals(request.Name));

            if (domain == null)
            {
                return(new Response <DeleteResult>(DeleteResult.NotFound));
            }

            if (domain.SubDomains.Any())
            {
                return(new Response <DeleteResult>(DeleteResult.NotDeletedDueToDependentObjects,
                                                   "The business domain cannot be deleted because it has child sub domains"));
            }

            _context.BusinessDomains.Remove(domain);
            await _context.SaveChangesAsync();

            return(new Response <DeleteResult>(DeleteResult.Deleted));
        }
예제 #18
0
        public async Task <Response <CreateResult> > Handle(CreateSubDomain request)
        {
            var businessDomain = await _context.BusinessDomains.SingleOrDefaultAsync(x => x.Name.Equals(request.ParentDomainName));

            if (businessDomain == null)
            {
                return(new Response <CreateResult>(CreateResult.DependentObjectNotFound));
            }

            var businessSubDomain = new BusinessSubDomain()
            {
                Id          = Guid.NewGuid(),
                Name        = request.Name,
                Description = request.Description,
                ParentId    = businessDomain.Id
            };

            await _context.AddAsync(businessSubDomain);

            await _context.SaveChangesAsync();

            return(new Response <CreateResult>(CreateResult.Created));
        }
        public async Task <Response <DeleteResult> > Handle(DeleteSubDomain request)
        {
            var subDomain = await _context.BusinessSubDomains
                            .FirstOrDefaultAsync(x => x.Name.Equals(request.Name));

            if (subDomain == null)
            {
                return(new Response <DeleteResult>(DeleteResult.NotFound));
            }

            var hasDependentApis = _context.Apis.Any(x => x.BusinessSubDomainId.Equals(subDomain.Id));

            if (hasDependentApis)
            {
                return(new Response <DeleteResult>(DeleteResult.NotDeletedDueToDependentObjects,
                                                   "The business sub domain cannot be deleted because it has APIs associated to it."));
            }

            _context.BusinessSubDomains.Remove(subDomain);
            await _context.SaveChangesAsync();

            return(new Response <DeleteResult>(DeleteResult.Deleted));
        }
예제 #20
0
        public async Task <Response <CreateResult> > Handle(CreateApiVersion request)
        {
            var api = await _context.Apis.SingleOrDefaultAsync(x => x.Name.Equals(request.ApiName));

            if (api == null)
            {
                return(new Response <CreateResult>(CreateResult.DependentObjectNotFound, "No API can be found with the supplied name"));
            }

            var apiVersion = new ApiVersion()
            {
                ApiId        = api.Id,
                MajorVersion = request.MajorVersion,
                MinorVersion = request.MinorVersion,
                Status       = VersionStatus.Inception
            };

            await _context.ApiVersions.AddAsync(apiVersion);

            await _context.SaveChangesAsync();

            return(new Response <CreateResult>(CreateResult.Created));
        }
예제 #21
0
        public async Task Handle(PersonRegisteredEvent message)
        {
            var p = new Person()
            {
                FirstName   = message.FirstName,
                LastName    = message.LastName,
                OriginalId  = message.PersonId,
                DisplayName = $"{message.FirstName} {message.LastName}",
                NationalIdentificationNumber = message.NationalIdentificationNumber,
                VatIndex     = message.VatNumber,
                LegalAddress = new PostalAddress
                {
                    Address    = message.Address,
                    City       = message.City,
                    Country    = message.Country,
                    PostalCode = message.PostalCode,
                    Province   = message.Province
                },
                ShippingAddress = new PostalAddress(),
                BillingAddress  = new PostalAddress(),
                ContactInfo     = new ContactInfo
                {
                    PhoneNumber      = message.PhoneNumber,
                    MobileNumber     = message.MobileNumber,
                    FaxNumber        = message.FaxNumber,
                    WebsiteAddress   = message.WebsiteAddress,
                    EmailAddress     = message.EmailAddress,
                    InstantMessaging = message.InstantMessaging
                }
            };

            using (var context = new RegistryDbContext())
            {
                context.Parties.Add(p);
                await context.SaveChangesAsync();
            }
        }
예제 #22
0
        public async Task Handle(PersonRegisteredEvent message)
        {
            var p = new Person()
            {
                FirstName   = message.FirstName,
                LastName    = message.LastName,
                OriginalId  = message.PersonId,
                DisplayName = $"{message.FirstName} {message.LastName}",
                NationalIdentificationNumber = message.NationalIdentificationNumber,
                VatIndex = message.VatNumber
                           //LegalAddress = new PostalAddress
                           //{
                           //    Address = message.Address,
                           //    City = message.City,
                           //    Country = message.Country,
                           //    PostalCode = message.PostalCode,
                           //    Province = message.Province
                           //},
                           //ShippingAddress = new PostalAddress(),
                           //BillingAddress = new PostalAddress(),
                           //ContactInfo = new ContactInfo
                           //{
                           //    PhoneNumber = message.PhoneNumber,
                           //    MobileNumber = message.MobileNumber,
                           //    FaxNumber = message.FaxNumber,
                           //    WebsiteAddress = message.WebsiteAddress,
                           //    EmailAddress = message.EmailAddress,
                           //    InstantMessaging = message.InstantMessaging
                           //}
            };

            using (var context = new RegistryDbContext(Options))
            {
                context.People.Add(p);
                await context.SaveChangesAsync();
            }
        }
예제 #23
0
        public async Task <Response <CreateResult> > Handle(CreateDomain request)
        {
            var businessDomainId = Guid.NewGuid();

            var businessDomain = new BusinessDomain()
            {
                Id          = businessDomainId,
                Name        = request.Name,
                Description = request.Description,
                SubDomains  = request.SubDomains.Select(x => new BusinessSubDomain()
                {
                    Id          = Guid.NewGuid(),
                    Description = x.Description,
                    Name        = x.Name,
                    ParentId    = businessDomainId
                }).ToList()
            };

            await _context.AddAsync(businessDomain);

            await _context.SaveChangesAsync();

            return(new Response <CreateResult>(CreateResult.Created));
        }
예제 #24
0
        public async Task <Response <UpdateResult> > Handle(UpdateDomain request)
        {
            var dbDomain = await _context.BusinessDomains
                           .Include(x => x.SubDomains)
                           .FirstOrDefaultAsync(x => x.Name.Equals(request.Name));

            if (dbDomain == null)
            {
                return(new Response <UpdateResult>(UpdateResult.NotFound));
            }
            else
            {
                if (!string.IsNullOrEmpty(request.NewName))
                {
                    dbDomain.Name = request.NewName;
                }

                if (request.UpdatedSubDomains != null)
                {
                    // new list to allow iteration over changing collection
                    foreach (var dbSubDomain in new List <BusinessSubDomain>(dbDomain.SubDomains))
                    {
                        var subDomain = request.UpdatedSubDomains.FirstOrDefault(x => x.Name == dbSubDomain.Name);
                        if (subDomain == null)
                        {
                            dbDomain.SubDomains.Remove(dbSubDomain);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(subDomain.NewName))
                            {
                                dbSubDomain.Name = subDomain.NewName;
                            }

                            if (!string.IsNullOrEmpty(subDomain.NewDescription))
                            {
                                dbSubDomain.Description = subDomain.NewDescription;
                            }
                        }
                    }

                    foreach (var subDomain in request.UpdatedSubDomains)
                    {
                        var dbSubDomain = dbDomain.SubDomains.FirstOrDefault(x => x.Name == subDomain.Name);
                        if (dbSubDomain == null)
                        {
                            dbDomain.SubDomains.Add(new BusinessSubDomain()
                            {
                                Name        = subDomain.Name,
                                Description = subDomain.NewDescription,
                                ParentId    = dbDomain.Id
                            });
                        }
                    }
                }

                await _context.SaveChangesAsync();

                return(new Response <UpdateResult>(UpdateResult.Updated));
            }
        }