예제 #1
0
        public void CreateParty(CreatePartyRequest request)
        {
            var customer = _customerService.GetCustomer(request.CustomerId);

            if (string.IsNullOrEmpty(customer.Phone.PhoneNumber))
            {
                throw new InvalidRequestException($"Customer {customer.Id} has not provided a phone number.");
            }
            if (!customer.Phone.IsVerified)
            {
                throw new InvalidRequestException($"Phone number for customer {customer.Id} has not been validated.");
            }

            var activeParty = GetParties(customer.Id, isActive: true);

            if (activeParty.Any())
            {
                throw new InvalidRequestException($"Customer {customer.Id} has an existing active party");
            }

            var party = new Party(request);

            _partyRepository.Add(party);
            _partyRepository.Save();
        }
예제 #2
0
        public Party CreateParty(string Name, Citizen foundator, Country originCountry)
        {
            var partyEntity = entityService.CreateEntity(Name, EntityTypeEnum.Party);
            var policies    = originCountry.CountryPolicy;

            Party party = new Party()
            {
                FoundationDay = GameHelper.CurrentDay,
                Foundator     = foundator,
                Entity        = partyEntity,
                JoinMethodID  = (int)JoinMethodEnum.Request,
                PartyMembers  = new List <PartyMember>(),
                Country       = originCountry
            };

            var foundatorCongressman = new PartyMember()
            {
                Citizen     = foundator,
                PartyRoleID = (int)PartyRoleEnum.President
            };

            party.PartyMembers.Add(foundatorCongressman);

            partyRepository.Add(party);
            partyRepository.SaveChanges();

            CreateNewPresidentVoting(party, GameHelper.CurrentDay + policies.PartyPresidentCadenceLength);

            return(party);
        }
        public override bool Add(Party party)
        {
            if (string.IsNullOrEmpty(party.Name))
            {
                throw new Exception("Party Name is not provided!");
            }

            if (string.IsNullOrEmpty(party.ContactNo))
            {
                throw new Exception("Party Contact No is not provided!");
            }


            return(_partyRepository.Add(party));
        }
예제 #4
0
        /// <summary>
        /// This method is self-committing
        /// </summary>
        public void ProcessFirstUserLogin()
        {
            using var transaction = DbContext.Database.BeginTransaction(IsolationLevel.Serializable);

            DbContext.Database.ExecuteSqlInterpolated($"SELECT 1 FROM HMR_SYSTEM_USER WITH(XLOCK, ROWLOCK) WHERE USERNAME = {_currentUser.UserName}");

            var userEntity = DbSet.First(u => u.Username == _currentUser.UniversalId);

            if (userEntity.UserGuid == null)
            {
                userEntity.UserGuid          = _currentUser.UserGuid;
                userEntity.BusinessGuid      = _currentUser.BusinessGuid;
                userEntity.BusinessLegalName = _currentUser.BusinessLegalName;
                userEntity.UserType          = _currentUser.UserType;
                //todo: uncomment after Keycloak implementation
                //userEntity.FirstName = _currentUser.FirstName;
                //userEntity.LastName = _currentUser.LastName;
                //userEntity.Email = _currentUser.Email;

                if (_currentUser.UserType == UserTypeDto.INTERNAL)
                {
                    DbContext.SaveChanges();
                    transaction.Commit();
                    return;
                }

                var partyEntity = _partyRepo.GetPartyEntityByGuid(_currentUser.BusinessGuid);

                if (partyEntity != null)
                {
                    return;
                }

                var party = new PartyDto
                {
                    BusinessGuid      = _currentUser.BusinessGuid,
                    BusinessLegalName = _currentUser.BusinessLegalName.Trim(),
                    BusinessNumber    = Convert.ToDecimal(_currentUser.BusinessNumber),
                    DisplayName       = _currentUser.BusinessLegalName.Trim()
                };

                _partyRepo.Add(party);
                DbContext.SaveChanges();
            }

            transaction.Commit();
        }
예제 #5
0
파일: PartyService.cs 프로젝트: fzck/DDD
 public void CreateParty(PartyDto partyDto)
 {
     _partyRepository.Add(new Party(partyDto.DisplayName));
     _partyRepository.unitOfWork._firstGenUnitOfWork.Commit();
 }