public async Task <IActionResult> Edit(int id, [Bind("Id,AffiliateId,ContractStatuId,ApplicationDate")] AffiliateContracts affiliateContracts)
        {
            if (id != affiliateContracts.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(affiliateContracts);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AffiliateContractsExists(affiliateContracts.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AffiliateId"]     = new SelectList(_context.Affiliates, "Id", "FirtsName", affiliateContracts.AffiliateId);
            ViewData["ContractStatuId"] = new SelectList(_context.ContractStatus, "Id", "Status", affiliateContracts.ContractStatuId);
            return(View(affiliateContracts));
        }
        public async Task <IActionResult> Create([Bind("Id,AffiliateId,ContractStatuId,ApplicationDate")] AffiliateContracts affiliateContracts)
        {
            var validReg = _context.AffiliateContracts.Where(x => x.AffiliateId == affiliateContracts.AffiliateId && x.ContractStatuId == 4).Count() == 0 ? true: false;

            if (ModelState.IsValid && validReg)
            {
                affiliateContracts.ContractStatuId = 4;
                affiliateContracts.ApplicationDate = DateTime.Now;

                _context.Add(affiliateContracts);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), "AffiliateContractServices", new { id = affiliateContracts.Id }));
            }
            else
            {
                ModelState.AddModelError("AffiliateId", "Can't create new request to contracts by has one pendenting to approve");
            }
            ViewData["AffiliateId"]     = new SelectList(_context.Affiliates, "Id", "FirtsName", affiliateContracts.AffiliateId);
            ViewData["ContractStatuId"] = new SelectList(_context.ContractStatus, "Id", "Status", affiliateContracts.ContractStatuId);
            return(View(affiliateContracts));
        }