예제 #1
0
        public TaskResult <int?> DoTask(RecordLabel recordLabel)
        {
            try
            {
                var address   = recordLabel.Address;
                var countryId = address.Country?.Id ?? address.CountryId;
                var country   = _dbContext.Countries.SingleOrDefault(c => c.Id == countryId);
                address.Country = country;
                _dbContext.Addresses.Add(address);
                _dbContext.SaveChanges();

                recordLabel.Address   = null;
                recordLabel.AddressId = address.Id;

                recordLabel.TaxId = _formattingService.FormatTaxId(recordLabel.TaxId);
                recordLabel.Phone = _formattingService.FormatPhoneNumber(recordLabel.Phone);

                _dbContext.RecordLabels.Add(recordLabel);
                _dbContext.SaveChanges();

                recordLabel.Address = address;

                return(new TaskResult <int?>(recordLabel.Id));
            }
            catch (Exception e)
            {
                return(new TaskResult <int?>(new TaskException(e)));
            }
        }
예제 #2
0
        public TaskResult <Nothing> DoTask(Publisher update)
        {
            try
            {
                var publisher = _dbContext.Publishers.Where(p => p.Id == update.Id)
                                .Include(p => p.Address)
                                .SingleOrDefault();

                if (publisher == null)
                {
                    throw new TaskException(SystemMessage("PUBLISHER_NOT_FOUND"));
                }

                publisher.Name  = update.Name;
                publisher.TaxId = _formattingService.FormatTaxId(update.TaxId);
                publisher.Email = update.Email;
                publisher.Phone = _formattingService.FormatPhoneNumber(update.Phone);

                if (update.Address != null)
                {
                    if (publisher.Address == null)
                    {
                        var address   = update.Address;
                        var countryId = address.Country?.Id ?? address.CountryId;
                        var country   = _dbContext.Countries.SingleOrDefault(c => c.Id == countryId);
                        address.Country = country;
                        _dbContext.Addresses.Add(address);
                        _dbContext.SaveChanges();
                        publisher.Address = address;
                    }
                    publisher.Address.Street     = update.Address.Street;
                    publisher.Address.City       = update.Address.City;
                    publisher.Address.Region     = update.Address.Region;
                    publisher.Address.PostalCode = update.Address.PostalCode;

                    publisher.Address.CountryId = update.Address.Country?.Id;
                    if (publisher.Address.CountryId.HasValue)
                    {
                        var country = _dbContext.Countries.SingleOrDefault(c => c.Id == publisher.Address.CountryId);
                        publisher.Address.Country = country ?? throw new TaskException(SystemMessage("COUNTRY_NOT_FOUND"));
                    }
                }

                publisher.PerformingRightsOrganizationId = update.PerformingRightsOrganization?.Id;
                if (publisher.PerformingRightsOrganizationId.HasValue)
                {
                    var pro = _dbContext.PerformingRightsOrganizations.SingleOrDefault(r => r.Id == publisher.PerformingRightsOrganizationId);
                    publisher.PerformingRightsOrganization = pro ?? throw new TaskException(SystemMessage("PRO_NOT_FOUND"));
                }
                publisher.PerformingRightsOrganizationPublisherNumber = update.PerformingRightsOrganizationPublisherNumber;

                _dbContext.SaveChanges();

                return(new TaskResult <Nothing>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <Nothing>(new TaskException(e)));
            }
        }
예제 #3
0
        public TaskResult <Nothing> DoTask(Artist update)
        {
            try
            {
                var artist = _dbContext.Artists
                             .SingleOrDefault(a => a.Id == update.Id);

                if (artist == null)
                {
                    throw new TaskException(SystemMessage("ARTIST_NOT_FOUND"));
                }

                artist.Name           = update.Name;
                artist.TaxId          = _formattingService.FormatTaxId(update.TaxId);
                artist.Email          = string.IsNullOrWhiteSpace(update.Email) ? null : update.Email;
                artist.HasServiceMark = update.HasServiceMark;
                artist.WebsiteUrl     = string.IsNullOrWhiteSpace(update.WebsiteUrl) ? null : update.WebsiteUrl;
                artist.PressKitUrl    = string.IsNullOrWhiteSpace(update.PressKitUrl) ? null : update.PressKitUrl;

                if (update.Address != null)
                {
                    if (artist.Address == null)
                    {
                        var address   = update.Address;
                        var countryId = address.Country?.Id ?? address.CountryId;
                        var country   = _dbContext.Countries.SingleOrDefault(c => c.Id == countryId);
                        address.Country = country;
                        _dbContext.Addresses.Add(address);
                        _dbContext.SaveChanges();
                        artist.Address = address;
                    }

                    artist.Address.Street     = update.Address.Street;
                    artist.Address.City       = update.Address.City;
                    artist.Address.Region     = update.Address.Region;
                    artist.Address.PostalCode = update.Address.PostalCode;
                    artist.Address.CountryId  = update.Address.Country?.Id;
                    if (artist.Address.CountryId.HasValue)
                    {
                        var country = _dbContext.Countries.SingleOrDefault(c => c.Id == artist.Address.CountryId);
                        artist.Address.Country = country ?? throw new TaskException(SystemMessage("COUNTRY_NOT_FOUND"));
                    }
                }

                artist.RecordLabelId = update.RecordLabel?.Id;
                if (artist.RecordLabelId.HasValue)
                {
                    var recordLabel = _dbContext.RecordLabels.SingleOrDefault(l => l.Id == artist.RecordLabelId);
                    artist.RecordLabel = recordLabel ?? throw new TaskException(SystemMessage("RECORD_LABEL_NOT_FOUND"));
                }

                _dbContext.SaveChanges();

                return(new TaskResult <Nothing>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <Nothing>(new TaskException(e)));
            }
        }
예제 #4
0
        public TaskResult <int?> DoTask(Artist artist)
        {
            try
            {
                var address   = artist.Address;
                var countryId = address.Country?.Id ?? address.CountryId;
                var country   = _dbContext.Countries.SingleOrDefault(c => c.Id == countryId);
                address.Country = country;
                _dbContext.Addresses.Add(address);
                _dbContext.SaveChanges();

                var recordLabelId = artist.RecordLabel?.Id ?? artist.RecordLabelId;

                artist.Address       = null;
                artist.AddressId     = address.Id;
                artist.RecordLabel   = null;
                artist.RecordLabelId = recordLabelId;

                artist.TaxId       = _formattingService.FormatTaxId(artist.TaxId);
                artist.Email       = string.IsNullOrWhiteSpace(artist.Email) ? null : artist.Email;
                artist.WebsiteUrl  = string.IsNullOrWhiteSpace(artist.WebsiteUrl) ? null : artist.WebsiteUrl;
                artist.PressKitUrl = string.IsNullOrWhiteSpace(artist.PressKitUrl) ? null : artist.PressKitUrl;

                _dbContext.Artists.Add(artist);
                _dbContext.SaveChanges();

                artist.Address     = address;
                artist.RecordLabel = recordLabelId > 0 ?
                                     _dbContext.RecordLabels.Where(r => r.Id == recordLabelId)
                                     .Include(r => r.Address).ThenInclude(a => a.Country)
                                     .SingleOrDefault() : null;

                return(new TaskResult <int?>(artist.Id));
            }
            catch (Exception e)
            {
                return(new TaskResult <int?>(new TaskException(e)));
            }
        }
        public TaskResult <Nothing> DoTask(RecordLabel update)
        {
            try
            {
                var recordLabel = _dbContext.RecordLabels.Where(l => l.Id == update.Id)
                                  .Include(p => p.Address)
                                  .SingleOrDefault();

                if (recordLabel == null)
                {
                    throw new TaskException(SystemMessage("RECORD_LABEL_NOT_FOUND"));
                }

                recordLabel.Name               = update.Name;
                recordLabel.TaxId              = _formattingService.FormatTaxId(update.TaxId);
                recordLabel.Email              = update.Email;
                recordLabel.Phone              = _formattingService.FormatPhoneNumber(update.Phone);
                recordLabel.Address.Street     = update.Address.Street;
                recordLabel.Address.City       = update.Address.City;
                recordLabel.Address.Region     = update.Address.Region;
                recordLabel.Address.PostalCode = update.Address.PostalCode;

                recordLabel.Address.CountryId = update.Address.Country?.Id;
                if (recordLabel.Address.CountryId.HasValue)
                {
                    var country = _dbContext.Countries.SingleOrDefault(c => c.Id == recordLabel.Address.CountryId);
                    recordLabel.Address.Country = country ?? throw new TaskException(SystemMessage("COUNTRY_NOT_FOUND"));
                }

                _dbContext.SaveChanges();

                return(new TaskResult <Nothing>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <Nothing>(new TaskException(e)));
            }
        }
예제 #6
0
        public TaskResult <int?> DoTask(Publisher publisher)
        {
            try
            {
                var address   = publisher.Address;
                var countryId = address.Country?.Id ?? address.CountryId;
                var country   = _dbContext.Countries.SingleOrDefault(c => c.Id == countryId);
                address.Country = country;
                _dbContext.Addresses.Add(address);
                _dbContext.SaveChanges();

                var proId = publisher.PerformingRightsOrganization?.Id ?? publisher.PerformingRightsOrganizationId;

                publisher.Address   = null;
                publisher.AddressId = address.Id;
                publisher.PerformingRightsOrganization   = null;
                publisher.PerformingRightsOrganizationId = proId;

                publisher.TaxId = _formattingService.FormatTaxId(publisher.TaxId);
                publisher.Phone = _formattingService.FormatPhoneNumber(publisher.Phone);

                _dbContext.Publishers.Add(publisher);
                _dbContext.SaveChanges();

                publisher.Address = address;
                publisher.PerformingRightsOrganization = proId > 0 ?
                                                         _dbContext.PerformingRightsOrganizations.Where(p => p.Id == proId)
                                                         .Include(p => p.Country)
                                                         .SingleOrDefault() : null;

                return(new TaskResult <int?>(publisher.Id));
            }
            catch (Exception e)
            {
                return(new TaskResult <int?>(new TaskException(e)));
            }
        }