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))); } }
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))); } }
public TaskResult <Nothing> DoTask(Person update) { try { var person = _dbContext.People.Where(p => p.Id == update.Id) .Include(p => p.Address) .SingleOrDefault(); if (person == null) { throw new TaskException(SystemMessage("PERSON_NOT_FOUND")); } person.FirstName = update.FirstName; person.MiddleName = string.IsNullOrWhiteSpace(update.MiddleName) ? null : update.MiddleName; person.LastName = update.LastName; person.NameSuffix = string.IsNullOrWhiteSpace(update.NameSuffix) ? null : update.NameSuffix; person.Email = string.IsNullOrWhiteSpace(update.Email) ? null : update.Email; person.Phone = _formattingService.FormatPhoneNumber(update.Phone); if (update.Address != null && !string.IsNullOrWhiteSpace(update.Address.Street)) { if (person.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(); person.Address = address; } person.Address.Street = update.Address.Street; person.Address.City = update.Address.City; person.Address.Region = update.Address.Region; person.Address.PostalCode = update.Address.PostalCode; person.Address.CountryId = update.Address.Country?.Id; if (person.Address.CountryId.HasValue) { var country = _dbContext.Countries.SingleOrDefault(c => c.Id == person.Address.CountryId); person.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))); } }
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))); } }
public TaskResult <int?> DoTask(Person person) { try { var address = person.Address; if (address != null && !string.IsNullOrWhiteSpace(address.Street)) { 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(); person.AddressId = address.Id; } person.Address = null; person.MiddleName = string.IsNullOrWhiteSpace(person.MiddleName) ? null : person.MiddleName; person.NameSuffix = string.IsNullOrWhiteSpace(person.NameSuffix) ? null : person.NameSuffix; person.Email = string.IsNullOrWhiteSpace(person.Email) ? null : person.Email; person.Phone = _formattingService.FormatPhoneNumber(person.Phone); _dbContext.People.Add(person); _dbContext.SaveChanges(); if (person.AddressId > 0) { person.Address = address; } return(new TaskResult <int?>(person.Id)); } catch (Exception e) { return(new TaskResult <int?>(new TaskException(e))); } }
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))); } }