Exemplo n.º 1
0
        /// <summary>
        /// Adds a new Family and the associated Insurees into the database
        /// </summary>
        /// <param name="family">The Family to be added</param>
        /// <returns></returns>
        public async Task <FamilyModel> AddNewFamilyAsync(FamilyModel family)
        {
            using (var imisContext = new ImisDB())
            {
                var tblFamily = family.ToTblFamilies();

                imisContext.Add(tblFamily);
                await imisContext.SaveChangesAsync();

                foreach (TblInsuree tblInsuree in tblFamily.TblInsuree)
                {
                    if (tblInsuree.IsHead)
                    {
                        tblFamily.InsureeId = tblInsuree.InsureeId;
                        break;
                    }
                }

                await imisContext.SaveChangesAsync();

                return(FamilyModel.FromTblFamilies(tblFamily));
            }
        }