public async Task <IActionResult> IndexBysignutre(int signutreId, List <LettersAndSignaturesModelView> model)
        {
            if (ModelState.IsValid)
            {
                var typeOfLettersToCreate = new List <TypesOfLettersAndSignature>();
                var typeOfLettersToDelete = new List <TypesOfLettersAndSignature>();

                foreach (var m in model)
                {
                    var typeOfLetter = new TypesOfLettersAndSignature()
                    {
                        SignatureId      = signutreId,
                        IsSignatureOwner = true,
                        StartAtDate      = DateTime.Now,
                        TypesOfletterId  = m.TypesOfletterId,
                        WonerSignatureId = null,
                        Id = m.TypeOfLetterAndSignutreId
                    };
                    if (m.TypeOfLetterAndSignutreId == 0 && m.IsSelected)
                    {
                        typeOfLettersToCreate.Add(typeOfLetter);
                    }
                    else if (m.TypeOfLetterAndSignutreId > 0 && m.IsSelected == false)
                    {
                        typeOfLettersToDelete.Add(typeOfLetter);
                    }
                }
                _context.AddRange(typeOfLettersToCreate);
                _context.RemoveRange(typeOfLettersToDelete);
                _context.RemoveRange(CancelTypesOfLettersAndSignatures(signutreId).Result);
                if (CancelDelegateToSignutre(signutreId).Result != null)
                {
                    _context.Update(CancelDelegateToSignutre(signutreId).Result);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Signatures"));
            }

            var sig = await _context.Signatures.Include(u => u.User)
                      .FirstOrDefaultAsync(s => s.Id == signutreId);

            ViewBag.Signutre   = sig != null ? sig.User.FullName : "";
            ViewBag.SignutreId = sig != null ? sig.Id : 0;
            return(View(model));
        }
        private async Task <List <TypesOfLettersAndSignature> > AddTypesOfLettersAndSignatures(int signutreId, int delegatednew)
        {
            var delegated = await _context.TypesOfLettersAndSignatures
                            .Where(s => s.SignatureId == signutreId)
                            .ToListAsync();

            var modelToAdd = new List <TypesOfLettersAndSignature>();

            foreach (var woner in delegated)
            {
                var added = new TypesOfLettersAndSignature()
                {
                    SignatureId      = delegatednew,
                    IsSignatureOwner = false,
                    StartAtDate      = DateTime.Now,
                    TypesOfletterId  = woner.TypesOfletterId,
                    WonerSignatureId = woner.Id,
                };
                modelToAdd.Add(added);
            }


            return(modelToAdd);
        }