Exemplo n.º 1
0
        public bool Add(Beneficiary beneficiary)
        {
            if (beneficiary != null)
            {
                _db.Add(beneficiary);
                if (_db.SaveChanges() == 1)
                {
                    return(true);
                }

                return(false);
            }
            return(false);
        }
Exemplo n.º 2
0
        public bool Add(Address address)
        {
            if (address != null)
            {
                _db.Add(address);
                if (_db.SaveChanges() == 1)
                {
                    return(true);
                }

                return(false);
            }
            return(false);
        }
        public bool Add(BeneficiaryTelephone telephones)
        {
            if (telephones != null)
            {
                _db.Add(telephones);
                if (_db.SaveChanges() == 1)
                {
                    return(true);
                }

                return(false);
            }
            return(false);
        }
Exemplo n.º 4
0
        public bool Add(Contract contract)
        {
            if (contract != null)
            {
                _db.Add(contract);
                if (_db.SaveChanges() == 1)
                {
                    return(true);
                }

                return(false);
            }
            return(false);
        }
        public bool Add(Telephone telephone)
        {
            if (telephone != null)
            {
                _db.Add(telephone);
                if (_db.SaveChanges() == 1)
                {
                    return(true);
                }

                return(false);
            }
            return(false);
        }
        public bool Add(Individual individual)
        {
            if (individual != null)
            {
                _db.Add(individual);
                if (_db.SaveChanges() == 1)
                {
                    return(true);
                }

                return(false);
            }
            return(false);
        }
        private void Seed()
        {
            using (var context = new ConfigurationContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var author = new User
                {
                    FirstName = "Tal",
                    LastName  = "Almog",
                    Email     = "abc",
                    Username  = "******"
                };

                author = new UserService(context).Register(author, "test-password");

                var content = new ConfigContent
                {
                    Content = JsonSerializer.Serialize(new { Port = 200 })
                };

                var system = new Microservice
                {
                    Name = "ConfigurationHub"
                };

                var config = new Config
                {
                    ConfigContent = content,
                    Author        = author,
                    Microservice  = system
                };

                context.Add(config);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Add de Contract Holder
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        public bool Add(ContractHolderViewModel vm)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required,
                                                    new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadCommitted
            }))
            {
                if (vm != null)
                {
                    // Individual
                    var individual = Factories.IndividualFactory.Create(vm);

                    if (individual == null)
                    {
                        return(false);
                    }
                    else if (_db.Individuals.Where(ind => (ind.IndividualCPF == individual.IndividualCPF) && (!ind.IsDeleted)).Any())
                    {
                        return(false);
                    }

                    _db.Add(individual);

                    // Telephone
                    if (vm.individualTelephones.Count() != 0)
                    {
                        var telephones = Factories.TelephoneFactory.CreateList(vm.individualTelephones);

                        if (telephones == null)
                        {
                            return(false);
                        }
                        else if (telephones.Count != vm.individualTelephones.Count)
                        {
                            return(false);
                        }

                        foreach (var telephone in telephones)
                        {
                            _db.Add(telephone);

                            _db.Add(new BeneficiaryTelephone
                            {
                                BeneficiaryTelephoneId = Guid.NewGuid(),
                                BeneficiaryId          = individual.BeneficiaryId,
                                TelephoneId            = telephone.TelephoneId
                            });
                        }
                    }

                    // Address
                    if (vm.individualAddresses.Count() != 0)
                    {
                        var addresses = Factories.AddressFactory.CreateList(vm.individualAddresses);

                        if (addresses == null)
                        {
                            return(false);
                        }
                        else if (addresses.Count != vm.individualAddresses.Count)
                        {
                            return(false);
                        }

                        foreach (var address in addresses)
                        {
                            _db.Add(address);

                            _db.Add(new BeneficiaryAddress
                            {
                                BeneficiaryAddressId = Guid.NewGuid(),
                                BeneficiaryId        = individual.BeneficiaryId,
                                AddressId            = address.AddressId
                            });
                        }
                    }

                    _db.SaveChanges();
                    scope.Complete();
                    return(true);
                }
                scope.Complete();
                return(false);
            }
        }