示例#1
0
        public async Task <ActionResult <PersonFamily> > PostPersonFamily(PersonFamily personFamily)
        {
            _context.PersonFamilies.Add(personFamily);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPersonFamily", new { id = personFamily.Id }, personFamily));
        }
示例#2
0
        public async Task <IActionResult> Edit(Guid id, [Bind("PersonId,FamilyId,Id,CreatedBy,CreatedAt,ChangedBy,ChangedAt")] PersonFamily personFamily)
        {
            if (id != personFamily.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(personFamily);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonFamilyExists(personFamily.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FamilyId"] = new SelectList(_context.Families, "Id", "FamilyName", personFamily.FamilyId);
            ViewData["PersonId"] = new SelectList(_context.Persons, "Id", "FirstName", personFamily.PersonId);
            return(View(personFamily));
        }
示例#3
0
        public async Task <IActionResult> PutPersonFamily(Guid id, PersonFamily personFamily)
        {
            if (id != personFamily.Id)
            {
                return(BadRequest());
            }

            _context.Entry(personFamily).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonFamilyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#4
0
        private void BtnSelectPerson_Click(object sender, RoutedEventArgs e)
        {
            var winPersonSearch = new WinPersonSearch();

            winPersonSearch.ShowDialog();
            if (winPersonSearch.PersonId == 0)
            {
                return;
            }

            if (PersonId.Contains(winPersonSearch.PersonId))
            {
                Utility.Message("خطا", "این شخص یک‌بار انتخاب شده است", "Stop.png");
                return;
            }
            PersonId.Add(winPersonSearch.PersonId);
            PersonName.Add(winPersonSearch.PersonName);
            PersonFamily.Add(winPersonSearch.PersonFamily);
            PersonFather.Add(winPersonSearch.PersonFather);
            PersonCode.Add(winPersonSearch.PersonCode);
            _createPersons = new List <CreatePerson>();
            for (var i = 0; i < PersonId.Count; i++)
            {
                _createPersons.Add(new CreatePerson(PersonId[i], PersonName[i], PersonFamily[i], PersonFather[i],
                                                    PersonCode[i]));
            }
            DgdPerson.ItemsSource = _createPersons;
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("PersonId,FamilyId,Id,CreatedBy,CreatedAt,ChangedBy,ChangedAt")] PersonFamily personFamily)
        {
            if (ModelState.IsValid)
            {
                personFamily.Id = Guid.NewGuid();
                _context.Add(personFamily);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FamilyId"] = new SelectList(_context.Families, "Id", "FamilyName", personFamily.FamilyId);
            ViewData["PersonId"] = new SelectList(_context.Persons, "Id", "FirstName", personFamily.PersonId);
            return(View(personFamily));
        }
        public void AddPersonToFamily(int id, int personId)
        {
            Family family = this.GetRepository().GetById(id)
                            ?? throw new InvalidPrimaryKeyException(typeof(Family).Name);

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            PersonFamily personFamily = new PersonFamily()
            {
                FamilyID = id, PersonID = personId
            };

            this.UnitOfWork.PersonFamilyRepository.Add(personFamily);
            this.UnitOfWork.SaveChanges();
        }
示例#7
0
 private void BtnDeletePerson_Click(object sender, RoutedEventArgs e)
 {
     if (DgdPerson.SelectedIndex == -1)
     {
         return;
     }
     PersonId.RemoveAt(DgdPerson.SelectedIndex);
     PersonName.RemoveAt(DgdPerson.SelectedIndex);
     PersonFamily.RemoveAt(DgdPerson.SelectedIndex);
     PersonFather.RemoveAt(DgdPerson.SelectedIndex);
     PersonCode.RemoveAt(DgdPerson.SelectedIndex);
     _createPersons = new List <CreatePerson>();
     for (var i = 0; i < PersonId.Count; i++)
     {
         _createPersons.Add(new CreatePerson(PersonId[i], PersonName[i], PersonFamily[i], PersonFather[i],
                                             PersonCode[i]));
     }
     DgdPerson.ItemsSource = _createPersons;
 }
        public void Create(int personId, string name)
        {
            CheckArgument.CheckForNull(name, nameof(name));

            Person person = this.UnitOfWork.PersonRepository.GetById(personId)
                            ?? throw new InvalidForeignKeyException(typeof(Person).Name);

            Family family = new Family()
            {
                Name = name
            };

            this.GetRepository().Add(family);

            PersonFamily personFamily = new PersonFamily {
                PersonID = personId, FamilyID = family.ID
            };

            this.UnitOfWork.PersonFamilyRepository.Add(personFamily);
            this.UnitOfWork.SaveChanges();
        }