/// <summary> /// Adds or updates the family. /// </summary> /// <param name="family">The family.</param> /// <exception cref="ArgumentNullException">family</exception> public async Task AddOrUpdate(FamilyDto family) { if (family is null) { throw new ArgumentNullException(nameof(family)); } var mdl = Map(family); using (var conn = new MySqlConnection(this.connStr)) { // open connection, so that all commands use the same one conn.Open(); string sql; // ID is not autonumber, so read db to check whether it already exists sql = "SELECT count(1) FROM family WHERE id = @Id"; int count = await conn.ExecuteScalarAsync <int>(sql, new { mdl.Id }).ConfigureAwait(false); if (count == 0) { sql = "INSERT INTO family (id, marriage_date, marriage_place, divorce_date, divorce_place) " + "VALUES (@Id, @MarriageDateInt, @MarriagePlace, @DivorceDateInt, @DivorcePlace)"; } else { sql = "UPDATE family SET id=@Id, marriage_date=@MarriageDateInt, marriage_place=@MarriagePlace, " + "divorce_date=@DivorceDateInt, divorce_place=@DivorcePlace " + "WHERE id = @Id"; } await conn.ExecuteAsync(sql, mdl).ConfigureAwait(false); } }
public ResponseDto <FamilyDto> Login(FamilyDto family) { ResponseDto <FamilyDto> response = new ResponseDto <FamilyDto>(); FamilyModel familyModel = new FamilyModel(); if (familyModel.ExistFamily(family.FamilyName) != null) { if (familyModel.ValidateFamily(family.FamilyName, family.Password) != null) { response.header.Message = ResponseMessages.SuccessMessage.Message; response.header.Code = ResponseMessages.SuccessMessage.Code; response.Data = familyModel.ValidateFamily(family.FamilyName, family.Password); } else { response.header.Message = ResponseMessages.InvalidUser.Message; response.header.Code = ResponseMessages.InvalidUser.Code; } } else { response.header.Message = ResponseMessages.NotFoundRegister.Message; response.header.Code = ResponseMessages.NotFoundRegister.Code; } return(response); }
public void UpdateFamily_AddFatherAndAMother_ThePatientHasAFatherAndAMother() { var cmp = new UnitTestComponent(this.Session); var users = cmp.GetPatientsByNameLight("*", SearchOn.FirstAndLastName); Assert.Greater(users.Count, 4, "Not enought data to execute the test"); var family = new FamilyDto() { Current = users[0], }; family.Father = users[1]; this.ComponentUnderTest.AddNewParent(users[1], users[2]); var persistedFamily = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(users[1].Id, family.Father.Id, "The father has an unexpected ID"); var family2 = new FamilyDto() { Current = users[0], }; family.Mother = users[2]; this.ComponentUnderTest.AddNewParent(users[1], users[3]); var persistedFamily2 = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(users[1].Id, family.Father.Id, "The father has an unexpected ID"); Assert.AreEqual(users[2].Id, family.Mother.Id, "The child has an unexpected ID"); }
/// <summary> /// Called when a GET request occurs. /// </summary> public async Task <IActionResult> OnGet() { PageStack.PushPage(HttpContext.Session, "/Admin/EditFamily", $"id={Id}"); if (this.Id <= 0) { // create new family // todo: who are the spouses? this.MarriageDate = new MutableGeneaDate(); } else { FamilyDto fam = await this.treeService.GetFamilyById(this.Id).ConfigureAwait(false); if (fam is null) { // explicit ID not found return(RedirectToPage("Index")); } this.MarriageDate = new MutableGeneaDate(fam.MarriageDate); this.MarriagePlace = fam.MarriagePlace; this.DivorceDate = new MutableGeneaDate(fam.DivorceDate); this.DivorcePlace = fam.DivorcePlace; this.FamilyName = string.Join(" and ", fam.Spouses.Select(sp => $"{sp.Firstnames}")); } return(Page()); }
public void Execute(UIApplication app) { Transaction trans = new Transaction(app.ActiveUIDocument.Document, "Получить выбранные семейства"); trans.Start(); UIDocument uidoc = app.ActiveUIDocument; Autodesk.Revit.DB.Document doc = uidoc.Document; Selection sel = app.ActiveUIDocument.Selection; ICollection <Autodesk.Revit.DB.ElementId> selectedIds = uidoc.Selection.GetElementIds(); //Reference annotation = sel.PickObject(ObjectType.Element, "Select item"); FamilyInstance elem = doc.GetElement(selectedIds.FirstOrDefault()) as FamilyInstance; FamilySymbol familySymbol = elem.Symbol; FamilyDto famDto = new FamilyDto(); if (FamilyName == null || FamilyName == "") { famDto.Name = familySymbol.Name; } else { famDto.Name = FamilyName; } famDto.FamilySymbolDto = familySymbol; famDto.ImagePath = Path; famDto.ID = familySymbol.Id.ToString(); MainWindowViewModel.familyDto = famDto; //MainWindowViewModel.FamilySymbolList.Add(famDto); trans.Commit(); ChangeUI?.Invoke(this); }
public Task AddOrUpdate(FamilyDto family) { if (family is null) { throw new System.ArgumentNullException(nameof(family)); } return(AddOrUpdateImpl(family)); async Task AddOrUpdateImpl(FamilyDto fam2) { var fam = fam2.Id == 0 ? null : await this.context.Families.FirstOrDefaultAsync(f => f.Id == fam2.Id).ConfigureAwait(false); if (fam == null) { if (fam2.Id == 0) { fam2.Id = (await this.context.Families.Select(i => i.Id).MaxAsync().ConfigureAwait(false)) + 1; } fam = new Family { Id = fam2.Id }; this.context.Families.Add(fam); } fam.IsDeleted = false; fam.MarriageDateInt = fam2.MarriageDate?.ToInt32(); fam.MarriagePlace = fam2.MarriagePlace; fam.DivorceDateInt = fam2.DivorceDate?.ToInt32(); fam.DivorcePlace = fam2.DivorcePlace; await this.context.SaveChangesAsync().ConfigureAwait(false); } }
public void UpdateFamily_AddFatherAndAChild_ThePatientHasAFatherAndAChild() { var users = this.HelperComponent.GetPatientsByNameLight("*", SearchOn.FirstAndLastName); Assert.Greater(users.Count, 4, "Not enought data to execute the test"); var family = new FamilyDto() { Current = users[0], }; family.Father = users[1]; this.ComponentUnderTest.AddNewChild(users[0], users[1]); var persistedFamily = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(users[1].Id, family.Father.Id, "The father has an unexpected ID"); var family2 = new FamilyDto() { Current = users[0], }; family.Children.Add(users[2]); this.ComponentUnderTest.AddNewChild(users[0], users[2]); var persistedFamily2 = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(users[1].Id, family.Father.Id, "The father has an unexpected ID"); Assert.AreEqual(users[2].Id, family.Children[0].Id, "The child has an unexpected ID"); }
public void IsInvalid() { var item = new FamilyDto() { Current = null, }; Assert.IsFalse(item.IsValid()); }
private Family Map(FamilyDto dto) => new Family { Id = dto.Id, MarriageDateInt = dto.MarriageDate?.ToInt32(), MarriagePlace = dto.MarriagePlace, DivorceDateInt = dto.DivorceDate?.ToInt32(), DivorcePlace = dto.DivorcePlace, };
public void IsValid() { var item = new FamilyDto() { Current = new LightPatientDto() { }, }; Assert.IsTrue(item.IsValid()); }
public void SaveFamily(FamilyDto family) { Family familyEntity = new Family { Name = family.Name, Description = family.Description }; _unitOfWork.FamilyRepository.Insert(familyEntity); _unitOfWork.Commit(); }
public async Task <IActionResult> Get(int id) { FamilyDto family = await familyService.GetFamilyAsync(id); if (family == null) { return(NotFound()); } var familyViewModel = mapper.Map <FamilyDto, FamilyViewModel>(family); return(Ok(familyViewModel)); }
protected override async Task Handle(FamilyCreationEvent e, CancellationToken cancellation) { if (_familyService.GetByName(e.FamilyName) != null) { Log.Info("[FAMILY][CREATION] NAME_ALREADY_TAKEN"); return; } if (e.Leader.HasFamily) { Log.Info("[FAMILY][CREATION] ALREADY_IN_FAMILY"); return; } var family = new FamilyDto { Name = e.FamilyName, FamilyFaction = FactionType.Angel, FamilyHeadGender = e.Leader.Character.Gender, FamilyMessage = string.Empty, MaxSize = 50, }; family = await _familyService.SaveAsync(family); // todo family object shared across all entities await AttachFamily(e.Leader, family, FamilyAuthority.Head); await e.Leader.BroadcastAsync(e.Leader.GenerateGidxPacket()); await e.Leader.SendPacketAsync(e.Leader.GenerateGInfoPacket()); if (e.Assistants == null) { return; } foreach (IPlayerEntity player in e.Assistants) { if (player.HasFamily) { continue; } await AttachFamily(player, family, FamilyAuthority.Assistant); await player.BroadcastAsync(player.GenerateGidxPacket()); await player.SendPacketAsync(player.GenerateGInfoPacket()); } }
/// <summary> /// Método para registrar familia. /// </summary> /// <param name="family"></param> /// <returns></returns> public FamilyDto RegisterFamily(FamilyDto family) { using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { var familyCreated = new Family(); familyCreated.FamilyName = family.FamilyName; familyCreated.Image = family.Image; familyCreated.Password = family.Password; dataContext.Family.Add(familyCreated); dataContext.SaveChanges(); family.IdFamily = familyCreated.IdFamily; } return(family); }
private async Task AttachFamily(IPlayerEntity player, FamilyDto family, FamilyAuthority authority) { if (family == null) { return; } player.Family = family; player.FamilyCharacter = await _characterFamilyService.SaveAsync(new CharacterFamilyDto { Authority = authority, CharacterId = player.Character.Id, FamilyId = family.Id, Rank = 0 }); }
public IActionResult Post(FamilyDto family) { try { if (!ModelState.IsValid) { return(BadRequest()); } _familyService.SaveFamily(family); return(StatusCode(201)); } catch (Exception) { return(StatusCode(500)); } }
public async Task <IActionResult> OnPost() { // this.Family.DivorceDate = value?.ToGeneaDate(); FamilyDto fam = await this.treeService.GetFamilyById(this.Id).ConfigureAwait(false); if (fam != null) { fam.MarriageDate = this.MarriageDate.ToGeneaDate(); fam.MarriagePlace = this.MarriagePlace; fam.DivorceDate = this.DivorceDate.ToGeneaDate(); fam.DivorcePlace = this.DivorcePlace; await this.treeService.Update(fam).ConfigureAwait(false); } return(RedirectToPage("Back")); }
public FamilyViewModel CreateViewModel(FamilyDto family) { if (family != null && family.Family != null) { return(new FamilyViewModel() { Id = family.Family.Id, IsActive = family.Family.IsActive, Name = family.Family.Name, Members = new MembersViewModel() { FamilyId = family.Family.Id, Members = family.Members } }); } return(null); }
public Task Update(FamilyDto family) { if (family is null) { throw new ArgumentNullException(nameof(family)); } if (family.Id <= 0) { throw new ArgumentException("ID must be greater than zero."); } return(UpdateImpl(family)); async Task UpdateImpl(FamilyDto fam) { await this.familyRepository.AddOrUpdate(fam).ConfigureAwait(false); } }
public ResponseDto <FamilyDto> RegisterFamily(FamilyDto family) { ResponseDto <FamilyDto> response = new ResponseDto <FamilyDto>(); FamilyModel familyModel = new FamilyModel(); if (familyModel.ExistFamily(family.FamilyName) == null) { response.Data = familyModel.RegisterFamily(family); response.header.Message = ResponseMessages.SuccessMessage.Message; response.header.Code = ResponseMessages.SuccessMessage.Code; } else { response.header.Message = ResponseMessages.RepeatedRegister.Message; response.header.Code = ResponseMessages.RepeatedRegister.Code; } return(response); }
/// <summary> /// Método para validar que la familia exista. /// </summary> /// <param name="FamilyName"></param> /// <returns></returns> public FamilyDto ValidateFamily(string FamilyName, string password) { var family = new FamilyDto(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.Family.Count(x => x.FamilyName.Trim().Equals(FamilyName.Trim()) && x.Password.Equals(password)) > 0) { var familyQuery = dataContext.Family .FirstOrDefault(x => x.FamilyName.Trim().Equals(FamilyName.Trim()) && x.Password.Equals(password)); family.FamilyName = familyQuery.FamilyName; family.Image = familyQuery.Image; family.IdFamily = familyQuery.IdFamily; } else { family = null; } } return(family); }
public async Task <FamilyDto> GetByIdWithMembersAsync(int familyId) { var result = new FamilyDto(); result.Family = await _dbContext.Families .Where(c => c.Id == familyId) .FirstOrDefaultAsync(); if (result.Family != null) { result.Members = await _dbContext.Users .Where(c => c.Family.Id == familyId) .Select(c => new FamilyMemberDto() { Email = c.Email }) .ToListAsync(); } return(result); }
/// <summary> /// Método para verificar que la familia este registrada. /// </summary> /// <param name="familyName"></param> /// <returns></returns> public FamilyDto ExistFamily(string familyName) { var family = new FamilyDto(); using (DutiesFamilyEntities dataContext = new DutiesFamilyEntities()) { if (dataContext.Family.Count(x => x.FamilyName.Trim().Equals(familyName.Trim())) > 0) { var familyQuery = dataContext.Family .FirstOrDefault(x => x.FamilyName.Trim().Equals(familyName.Trim())); family.FamilyName = familyQuery.FamilyName; family.Image = familyQuery.Image; family.IdFamily = familyQuery.IdFamily; } else { family = null; } } return(family); }
/// <summary> /// Convert a family into a list of patient. It fills up the Segratator to allow grouping /// the patients by family link /// </summary> /// <param name="family">The family.</param> /// <returns></returns> public static IEnumerable <LightPatientDto> ToPatients(this FamilyDto family) { var patients = new List <LightPatientDto>(); if (family.Father != null) { family.Father.Segretator = Messages.Msg_Father; patients.Add(family.Father); } if (family.Mother != null) { family.Mother.Segretator = Messages.Msg_Mother; patients.Add(family.Mother); } foreach (var child in family.Children) { child.Segretator = Messages.Msg_Children; patients.Add(child); } return(patients.ToArray()); }
public FamilyVm(FamilyDto dto) { if (dto is null) { throw new ArgumentNullException(nameof(dto)); } this.Id = dto.Id; this.MarriageDate = dto.MarriageDate; this.MarriagePlace = dto.MarriagePlace; this.DivorceDate = dto.DivorceDate; this.DivorcePlace = dto.DivorcePlace; foreach (var sp in dto.Spouses) { AddSpouse(new IndividualVm(sp)); } foreach (var ch in dto.Children) { this.Children.Add(new IndividualVm(ch)); } }
private async Task <FamilyDto> Map(Family db, bool includeDeleted) { var res = new FamilyDto { Id = db.Id, MarriageDate = db.MarriageDateInt == null ? null : new FamilyTreeNet.Core.Support.GeneaDate(db.MarriageDateInt.Value), MarriagePlace = db.MarriagePlace, DivorceDate = db.DivorceDateInt == null ? null : new FamilyTreeNet.Core.Support.GeneaDate(db.DivorceDateInt.Value), DivorcePlace = db.DivorcePlace, }; foreach (var spouse in db.Spouses) { res.Spouses.Add(await this.individualRepository.GetById(spouse.SpouseId, includeDeleted).ConfigureAwait(false)); } foreach (var child in db.Children) { res.Children.Add(await this.individualRepository.GetById(child.ChildId, includeDeleted).ConfigureAwait(false)); } return(res); }
public FamilyDto AddFamily(FamilyDto family) { context.Families.Add(family); context.SaveChanges(); return(family); }