Exemple #1
0
        public async Task saveClientChapter(ChapterClientDto payload)
        {
            ChapterClient cc = null;

            if (payload.Id != null)
            {
                cc = await _context.ChapterClient.FirstOrDefaultAsync(cc => cc.Id == payload.Id);

                clientChapterBuilder(ref payload, ref cc);
                _context.ChapterClient.Update(cc);
            }
            else
            {
                cc = new ChapterClient();
                clientChapterBuilder(ref payload, ref cc);
                await _context.ChapterClient.AddAsync(cc);
            }
            if (payload.Primary == true)
            {
                var removeFromPrimary = await _context.ChapterClient.Where(ch => ch.ClientId == cc.ClientId && cc.Id != ch.Id).ToListAsync();

                removeFromPrimary.ForEach(el =>
                {
                    el.Primary = false;
                });
                _context.ChapterClient.UpdateRange(removeFromPrimary);
            }
            await _context.SaveChangesAsync();
        }
Exemple #2
0
 private static void clientChapterBuilder(ref ChapterClientDto payload, ref ChapterClient cc)
 {
     cc.RegistrationDate = payload.RegistrationDate;
     cc.ChapterId        = payload.ChapterId.GetValueOrDefault();
     cc.ClientId         = payload.ClientId.GetValueOrDefault();
     cc.Primary          = payload.Primary;
     cc.NewRegistration  = payload.NewRegistration;
     cc.UpdatedAt        = DateTime.Now;
 }
Exemple #3
0
 private void ClientChapterAssociationBuilder(List <BonaFidesDto> payload, int clientId)
 {
     payload.ForEach(bn =>
     {
         var ch              = new ChapterClient();
         ch.ChapterId        = bn.Chapter.ChapterId.GetValueOrDefault();
         ch.ClientId         = clientId;
         ch.Primary          = bn.Chapter.Primary;
         ch.NewRegistration  = bn.Chapter.NewRegistration;
         ch.RegistrationDate = bn.Chapter.RegistrationDate;
         ch.UpdatedAt        = DateTime.Now;
         _context.ChapterClient.Add(ch);
     });
 }