Beispiel #1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Person person;

                string personId = ( string )Page.RouteData.Values["PersonId"] ?? string.Empty;
                if (string.IsNullOrEmpty(personId))
                {
                    personId = Request.QueryString["PersonId"];
                }

                PersonService personService = new PersonService();

                if (!string.IsNullOrEmpty(personId))
                {
                    person = personService.Get(Convert.ToInt32(personId));
                }
                else
                {
                    person = new Person();
                    personService.Add(person, CurrentPersonId);
                }

                person.GivenName = txtFirstName.Text;
                person.NickName  = txtNickName.Text;
                person.LastName  = txtLastName.Text;
                if (person.Guid == Guid.Empty)
                {
                    personService.Add(person, CurrentPersonId);
                }
                personService.Save(person, CurrentPersonId);
            }
        }
        public void Add_WhenPersonIsValid_ShouldCallRepository()
        {
            _personMock.Setup(x => x.IsValid()).Returns(true);

            _service.Add(_personMock.Object);

            _repositoryMock.Verify(x => x.Add(_personMock.Object), Times.Once);
        }
 public int MatchOrCreatePerson(PersonMatch personMatch)
 {
     try
     {
         Person        person        = personMatch.person;
         Location      location      = personMatch.location;
         RockContext   context       = new RockContext();
         PersonService personService = new PersonService(context);
         var           matchPerson   = personService.GetByMatch(person.FirstName, person.LastName, person.BirthDate, person.Email, person.PhoneNumbers.Select(pn => pn.Number).FirstOrDefault(), location.Street1, location.PostalCode);
         if (matchPerson != null && matchPerson.Count() > 0)
         {
             return(matchPerson.FirstOrDefault().Id);
         }
         else
         {
             personService.Add(person);
             context.SaveChanges();
             return(person.Id);
         }
     }
     catch (Exception e)
     {
         GenerateResponse(HttpStatusCode.InternalServerError, e.Message);
         throw e;
     }
 }
Beispiel #4
0
        public void AddPersonTest()
        {
            //Arrange
            var testSubject = new PersonService(_personRepository.Object);
            var person      = new Person
            {
                PersonId        = 1,
                PersonAddress   = "Lahore",
                PersonTelephone = "923004400613",
                PersonName      = "Mustafa Ali Hassan",
                Location        = new List <Location>
                {
                    new Location
                    {
                        LocationOwner = 1
                    }
                }
            };

            _personRepository.Setup(a => a.Add(person));
            _personRepository.Setup(a => a.SaveChanges());

            //Execute
            var result = testSubject.Add(person);

            //Assert
            _personRepository.VerifyAll();
            Assert.AreEqual(result, true);
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                var    service = new PersonService();
                Person person  = this.GetPersonFromView();

                if (this.PersonId != 0)
                {
                    person.Id = this.PersonId;
                    service.Update(person);
                }
                else
                {
                    service.Add(person);
                }

                this.Master.ShowBottomSuccessMessageAjax("Person successfully saved.");
            }
            catch (Exception ex)
            {
                const string message = "Error occurred while trying to save person. ";
                this.Master.ShowBottomErrorMessageAjax(message + ex.Message);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Finds the person if they're logged in, or by email and name. If not found, creates a new person.
        /// </summary>
        /// <returns></returns>
        private Person FindPerson()
        {
            Person person;
            var    personService = new PersonService();

            if (CurrentPerson != null)
            {
                person = CurrentPerson;
            }
            else
            {
                person = personService.GetByEmail(txtEmail.Text)
                         .FirstOrDefault(p => p.FirstName == txtFirstName.Text && p.LastName == txtLastName.Text);
            }

            if (person == null)
            {
                person = new Person
                {
                    GivenName = txtFirstName.Text,
                    LastName  = txtLastName.Text,
                    Email     = txtEmail.Text,
                };

                personService.Add(person, CurrentPersonId);
                personService.Save(person, CurrentPersonId);
            }

            return(person);
        }
Beispiel #7
0
        private void submitButton_Click(object sender, RoutedEventArgs e)
        {
            byte[]            imageInByte;
            JpegBitmapEncoder encoder = new JpegBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(selectedImage));
            using (MemoryStream ms = new MemoryStream())
            {
                encoder.Save(ms);
                imageInByte = ms.ToArray();
            }

            //Storing into database
            Person        p  = new Person(personNameTextBox.Text, contactNoTextBox.Text, addressTextBox.Text, joinDate.SelectedDate.Value, bloodGroupComboBox.SelectionBoxItem.ToString(), imageInByte);
            PersonService ps = new PersonService();

            ps.Add(p);
            Query  = "Select ID, PASSWORD from Person";
            reader = DataAccess.GetData(Query);
            reader.Read();
            MessageBox.Show("Sign Up Successful \nID : " + reader.GetString(0) + " \nPassword : "******" \n *Please Keep Your Id and Password in mind", "Successful", MessageBoxButton.OK, MessageBoxImage.Information);
            using (SignIn signin = new SignIn())
            {
                signin.Show();
                this.Close();
            }
        }
        private void AddTeam_Clicked(object sender, RoutedEventArgs e)
        {
            var addTeamWindow = new AddTeamWindow(false);
            var windowRes     = addTeamWindow.ShowDialog();

            Trace.WriteLine(windowRes);
            if (windowRes.HasValue && !windowRes.Value)
            {
                Trace.WriteLine("We did not press the add button");
                return;
            }

            if (addTeamWindow.Team == null)
            {
                Trace.WriteLine("Team is null");
                return;
            }

            if (addTeamWindow.Coach == null)
            {
                Trace.WriteLine("Coach is null");
                return;
            }

            _teamService.Add(addTeamWindow.Team);
            _personService.Add(addTeamWindow.Coach);
            Teams.Add(addTeamWindow.Team);
        }
Beispiel #9
0
        /// <summary>
        /// Finds the person if they're logged in, or by email and name. If not found, creates a new person.
        /// </summary>
        /// <returns></returns>
        private Person FindPerson()
        {
            Person person;
            var    personService = new PersonService();

            if (CurrentPerson != null)
            {
                person = CurrentPerson;
            }
            else
            {
                person = personService.GetByEmail(tbEmail.Text)
                         .FirstOrDefault(p => p.FirstName == tbFirstName.Text && p.LastName == tbLastName.Text);
            }

            if (person == null)
            {
                var definedValue = DefinedValueCache.Read(new Guid(GetAttributeValue("DefaultConnectionStatus")));
                person = new Person
                {
                    FirstName = tbFirstName.Text,
                    LastName  = tbLastName.Text,
                    Email     = tbEmail.Text,
                    ConnectionStatusValueId = definedValue.Id,
                };

                personService.Add(person, CurrentPersonId);
                personService.Save(person, CurrentPersonId);
            }

            return(person);
        }
Beispiel #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Person person;

                string personId = ( string )Page.RouteData.Values["PersonId"] ?? string.Empty;
                if (string.IsNullOrEmpty(personId))
                {
                    personId = Request.QueryString["PersonId"];
                }

                PersonService personService = new PersonService();

                if (!string.IsNullOrEmpty(personId))
                {
                    person = personService.Get(Convert.ToInt32(personId));
                }
                else
                {
                    person = new Person();
                    personService.Add(person, CurrentPersonId);
                }

                txtFirstName.Text = person.FirstName;
                txtNickName.Text  = person.NickName;
                txtLastName.Text  = person.LastName;
            }
        }
Beispiel #11
0
        //Register user as user if verfication complete
        private void UserVerify(string name, string email, int gender, string password, int age)
        {
            Person        person        = new User(name, email, gender, password, age);
            PersonService personService = new PersonService();

            //check if email already exist
            if (personService.GetByEmail(email) == "non-exist")
            {
                if (personService.Add(person) == 1)
                {
                    MessageBox.Show("Record Added Successfully!");
                    Login login = new Login();
                    this.Hide();
                    login.Closed += (s, args) => this.Close();
                    login.Show();
                }
                else
                {
                    MessageBox.Show("Couldn't Add to database");
                }
            }
            else
            {
                MessageBox.Show("You are already in the database!");
            }
        }
        /// <summary>
        /// Handles the SaveClick event of the mdLinkConversation control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void mdLinkToPerson_SaveClick(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var personAliasService = new PersonAliasService(rockContext);
                var personService      = new PersonService(rockContext);

                // Get the Person Record from the selected conversation. (It should be a 'NamelessPerson' record type)
                int    namelessPersonAliasId = hfSelectedRecipientPersonAliasId.Value.AsInteger();
                var    phoneNumberService    = new PhoneNumberService(rockContext);
                Person namelessPerson        = personAliasService.GetPerson(namelessPersonAliasId);

                if (namelessPerson == null)
                {
                    // shouldn't happen, but just in case
                    return;
                }

                EntitySet mergeRequest = null;
                if (pnlLinkToExistingPerson.Visible)
                {
                    var existingPersonId = ppPerson.PersonId;
                    if (!existingPersonId.HasValue)
                    {
                        return;
                    }

                    var existingPerson = personService.Get(existingPersonId.Value);
                    mergeRequest = namelessPerson.CreateMergeRequest(existingPerson);
                    var entitySetService = new EntitySetService(rockContext);
                    entitySetService.Add(mergeRequest);

                    rockContext.SaveChanges();
                    hfSelectedRecipientPersonAliasId.Value = existingPerson.PrimaryAliasId.ToString();
                }
                else
                {
                    // new Person and new family
                    var newPerson = new Person();

                    newPersonEditor.UpdatePerson(newPerson, rockContext);

                    personService.Add(newPerson);
                    rockContext.SaveChanges();

                    mergeRequest = namelessPerson.CreateMergeRequest(newPerson);
                    var entitySetService = new EntitySetService(rockContext);
                    entitySetService.Add(mergeRequest);
                    rockContext.SaveChanges();

                    hfSelectedRecipientPersonAliasId.Value = newPerson.PrimaryAliasId.ToString();
                }

                RedirectToMergeRequest(mergeRequest);
            }

            mdLinkToPerson.Hide();
            LoadResponseListing();
        }
Beispiel #13
0
        public void Add_WhenPersonIsNotValid_ShouldNotCallRepository()
        {
            _personMock.Setup(x => x.Isvalid()).Returns(false);

            _service.Add(_personMock.Object);

            _repositoryMock.Verify(x => x.Add(_personMock.Object), Times.Never);
        }
Beispiel #14
0
 protected override void ProcessData()
 {
     foreach (var file in Files)
     {
         var df = DataFileParser.Parse(file);
         _service.Add(df.Items);
     }
 }
Beispiel #15
0
 public async Task <IActionResult> AddPerson([FromBody] Person person)
 {
     if (personService.Add(person))
     {
         return(Created("Successfully created", person));
     }
     return(BadRequest("Can't create new person"));
 }
Beispiel #16
0
        private void AddPerson(Donor donor)
        {
            PersonService personService = new PersonService();

            if (personService.Add(donor) == 1)
            {
                MessageBox.Show("Registration Done Successfully!");
            }
        }
        public void CreatePerson()
        {
            var mockPersonRepository   = Mock.Create <IPersonRepository>();
            var mockAgeGroupRepository = Mock.Create <IAgeGroupRepository>();
            var myPersonService        = new PersonService(mockPersonRepository, mockAgeGroupRepository);

            myPersonService.Add("", "", 1);
            Mock.Assert(() => mockPersonRepository.Create(Arg.IsAny <string>(), Arg.IsAny <string>(), Arg.IsAny <int>()), Occurs.Once());
        }
Beispiel #18
0
        public void PersonService_Save()
        {
            using (var personService = new PersonService(context.Object))
            {
                var newPerson = personService.Add(new Person());

                Assert.IsNotNull(newPerson);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Handles the SaveClick event of the mdLinkToPerson control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void mdLinkToPerson_SaveClick(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var personAliasService = new PersonAliasService(rockContext);
                var personService      = new PersonService(rockContext);

                int    namelessPersonId = hfNamelessPersonId.Value.AsInteger();
                Person namelessPerson   = personService.Get(namelessPersonId);

                if (namelessPerson == null)
                {
                    // shouldn't happen, but just in case
                    return;
                }

                EntitySet mergeRequest = null;
                if (pnlLinkToExistingPerson.Visible)
                {
                    var existingPersonId = ppPerson.PersonId;
                    if (!existingPersonId.HasValue)
                    {
                        return;
                    }

                    var existingPerson = personService.Get(existingPersonId.Value);

                    mergeRequest = namelessPerson.CreateMergeRequest(existingPerson);
                    var entitySetService = new EntitySetService(rockContext);
                    entitySetService.Add(mergeRequest);

                    rockContext.SaveChanges();
                }
                else
                {
                    // new Person and new family
                    var newPerson = new Person();

                    newPersonEditor.UpdatePerson(newPerson, rockContext);

                    personService.Add(newPerson);
                    rockContext.SaveChanges();

                    mergeRequest = namelessPerson.CreateMergeRequest(newPerson);
                    var entitySetService = new EntitySetService(rockContext);
                    entitySetService.Add(mergeRequest);
                    rockContext.SaveChanges();
                }

                RedirectToMergeRequest(mergeRequest);
            }

            mdLinkToPerson.Hide();
            BindGrid();
        }
Beispiel #20
0
        private static Person GetOrCreateNamelessPerson(string email, string phone, PersonService personService)
        {
            var namelessPersonRecordValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_NAMELESS).Id;
            int numberTypeMobileValueId     = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE).Id;
            var number = PhoneNumber.CleanNumber(phone);

            var personQryOptions = new Rock.Model.PersonService.PersonQueryOptions
            {
                IncludeNameless = true
            };

            var qry = personService.Queryable(personQryOptions).Where(p => p.RecordTypeValueId == namelessPersonRecordValueId);

            if (email.IsNotNullOrWhiteSpace())
            {
                qry = qry.Where(p => p.Email == email);
            }

            if (phone.IsNotNullOrWhiteSpace())
            {
                qry = qry.Where(p => p.PhoneNumbers.Select(pn => pn.Number == number).Any());
            }

            var people = qry.ToList();

            if (people.Count() == 1)
            {
                return(people.First());
            }

            //Didn't get just one person... Time to make a new one!
            var person = new Person();

            person.RecordTypeValueId = namelessPersonRecordValueId;

            if (email.IsNotNullOrWhiteSpace())
            {
                person.Email = email;
            }

            if (phone.IsNotNullOrWhiteSpace())
            {
                var smsPhoneNumber = new PhoneNumber();
                smsPhoneNumber.NumberTypeValueId  = numberTypeMobileValueId;
                smsPhoneNumber.Number             = number;
                smsPhoneNumber.IsMessagingEnabled = true;
                person.PhoneNumbers.Add(smsPhoneNumber);
            }

            personService.Add(person);
            (( RockContext )personService.Context).SaveChanges();

            person = personService.Get(person.Id);
            return(person);
        }
Beispiel #21
0
 /// <summary>
 /// 新增实体
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public int Add(Person p)
 {
     try
     {
         return(ps.Add(p));
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Beispiel #22
0
        public Person GetRockPerson()
        {
            Person person = GetPerson(this.Id);

            if (person != null)
            {
                return(person);
            }

            RockContext   rockContext   = new RockContext();
            PersonService personService = new PersonService(rockContext);

            var people = personService.GetByMatch(FirstName, LastName, null, Email);

            if (people.Count() == 1)
            {
                person = people.FirstOrDefault();

                person.LoadAttributes();
                person.SetAttributeValue(Constants.PERSON_ATTRIBUTE_KEY_RISEID, Id);
                person.SaveAttributeValue(Constants.PERSON_ATTRIBUTE_KEY_RISEID);

                SaveUserCreated(person);

                return(person);
            }
            else //Webprospect
            {
                person = new Person
                {
                    FirstName               = FirstName,
                    NickName                = FirstName,
                    LastName                = LastName,
                    Email                   = Email,
                    EmailPreference         = EmailPreference.EmailAllowed,
                    RecordTypeValueId       = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid()).Id,
                    ConnectionStatusValueId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_CONNECTION_STATUS_WEB_PROSPECT).Id,
                    RecordStatusValueId     = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING).Id,
                };

                personService.Add(person);
                PersonService.SaveNewPerson(person, rockContext);
                rockContext.SaveChanges();

                person.LoadAttributes();
                person.SetAttributeValue(Constants.PERSON_ATTRIBUTE_KEY_RISEID, Id);
                person.SaveAttributeValue(Constants.PERSON_ATTRIBUTE_KEY_RISEID);

                SaveUserCreated(person);

                return(person);
            }
        }
        public ActionResult <Person> Register(Person person)
        {
            // if (person. < 0) return BadRequest("user is empty ó no cumple");
            Person model = _personService.Add(person);

            if (model == null)
            {
                return(BadRequest(model));
            }
            Console.WriteLine("bueno bueno que paso aqui vale");
            return(Ok(model));
        }
        public void RockCleanup_Execute_ShouldUpdatePeopleWithFinancialPersonSavedAccountToAccountProtectionProfileHigh()
        {
            var personGuid = Guid.NewGuid();
            var personWithFinancialPersonBankAccount = new Person
            {
                FirstName = "Test",
                LastName  = personGuid.ToString(),
                Email     = $"{personGuid}@test.com",
                Guid      = personGuid
            };

            using (var rockContext = new RockContext())
            {
                var personService = new PersonService(rockContext);
                personService.Add(personWithFinancialPersonBankAccount);
                rockContext.SaveChanges();

                personWithFinancialPersonBankAccount = personService.Get(personWithFinancialPersonBankAccount.Id);

                var financialGateway    = new FinancialGatewayService(rockContext).Get("6432D2D2-32FF-443D-B5B3-FB6C8414C3AD".AsGuid());
                var creditCardTypeValue = DefinedTypeCache.Get(SystemGuid.DefinedType.FINANCIAL_CREDIT_CARD_TYPE.AsGuid()).DefinedValues.OrderBy(a => Guid.NewGuid()).First().Id;
                var currencyTypeValue   = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()).Id;
                var definedValueService = new DefinedValueService(rockContext);

                var financialPersonSavedAccount = new FinancialPersonSavedAccount
                {
                    Name                   = "Test Saved Account",
                    PersonAliasId          = personWithFinancialPersonBankAccount.PrimaryAliasId.Value,
                    FinancialGateway       = financialGateway,
                    FinancialPaymentDetail = new FinancialPaymentDetail
                    {
                        AccountNumberMasked = "1111",
                        CreditCardTypeValue = definedValueService.Get(creditCardTypeValue),
                        CurrencyTypeValue   = definedValueService.Get(currencyTypeValue),
                        NameOnCard          = "Test User"
                    }
                };

                var service = new FinancialPersonSavedAccountService(rockContext);
                service.Add(financialPersonSavedAccount);
                rockContext.SaveChanges();
            }

            ExecuteRockCleanupJob();

            using (var rockContext = new RockContext())
            {
                var actualPerson = new PersonService(rockContext).Get(personGuid);
                Assert.That.AreEqual(AccountProtectionProfile.High, actualPerson.AccountProtectionProfile);
            }
        }
        public async Task ShouldCallAddPersonTest()
        {
            var repository = new Mock <IPersonRepository>();
            var personDto  = new PersonDto()
            {
                Name = "Charles",
            };

            var service = new PersonService(repository.Object);
            await service.Add(personDto);

            repository
            .Verify(x => x.Add(It.Is <Person>(y => y.Name == personDto.Name)), Times.Once());
        }
Beispiel #26
0
        public async Task <BusinessResult <long> > Add(PersonApp instance)
        {
            var domainModel = Mapper.Map <Person>(instance);

            var domainResult = await PersonService.Add(domainModel);

            var result = new BusinessResult <long>()
            {
                Success = domainResult > 0,
                Value   = domainResult
            };

            return(result);
        }
Beispiel #27
0
        public IActionResult Add([FromBody] Person person)
        {
            try {
                if (!person.IsValid())
                {
                    return(new BadRequestResult());
                }

                _service.Add(person);

                return(new OkResult());
            } catch (System.Exception) {
                return(new StatusCodeResult((int)HttpStatusCode.ServiceUnavailable));
            }
        }
Beispiel #28
0
 //Verify Admin
 void VerifyAdmin()
 {
     if (KeyTextBox.Text.ToString() == "")
     {
         MessageBox.Show("Please provide the key given by the root admin!");
     }
     else
     {
         try
         {
             key = int.Parse(KeyTextBox.Text.ToString());
             Person person = new Admin(name, email, gender, password, age, key);
             //check if key is matched
             if (person.KeyCheck == 1)
             {
                 PersonService personService = new PersonService();
                 //Check if email already exist
                 if (personService.GetByEmail(email) == "non-exist")
                 {
                     if (personService.Add(person) == 1)
                     {
                         MessageBox.Show("You are an Admin now!");
                         Login login = new Login();
                         this.Hide();
                         login.Closed += (s, args) => this.Close();
                         login.Show();
                     }
                     else
                     {
                         MessageBox.Show("Couldn't Add to database");
                     }
                 }
                 else
                 {
                     MessageBox.Show("You are already in the database!");
                 }
             }
             else
             {
                 MessageBox.Show("Contact With Admin For The Key!");
             }
         }
         catch (FormatException)
         {
             MessageBox.Show("Key should be a number");
         }
     }
 }
Beispiel #29
0
        public async Task Save()
        {
            IsBusy = true;
            person = new Person()
            {
                Id        = Guid.NewGuid().ToString(),
                FirstName = FirstName,
                LastName  = LastName,
                Age       = Age
            };
            await Task.Delay(2000);

            service.Add(person);
            Clear();
            IsBusy = false;
        }
Beispiel #30
0
        private void Submit(object sender, RoutedEventArgs e)
        {
            Person p = new Person();

            p.Name = nameBox.Text;
            //dob.Value().ToString();
            p.Id    = idBox.Text;
            p.Image = image2.Source.ToString();
            p.Date  = dob.SelectedDate.Value.Date;
            PersonService ps = new PersonService();

            if (ps.Add(p) > 0)
            {
                MessageBox.Show("Added Successfully");
            }
        }