Esempio n. 1
0
        public async Task<ActionResult> Sign(SignViewModel model, string repoOwner, string repoName) 
        {
            var repository = DataContext.Repositories.Where(repoOwner, repoName);
            ViewBag.LicenseText = repository.LicenseText;

            if (!ModelState.IsValid)
                return View(model);

            if (repository == null) // can't save if the repo doesn't require CLA's
                return new RedirectResult(string.Format("/{0}/{1}/sign/", repoOwner, repoName));

            var redirectUrl = string.Format("/{0}/{1}/", repoOwner, repoName);

            var user = DataContext.Signatures.Where(repoOwner, repoName, User.Identity);
            if (user != null)// redirect user if they have already signed the CLA (CLA's can't be changed
            {
                TempData["userSigned"] = new UserSignedNotification("success", User.Identity.Name);
                return new RedirectResult(redirectUrl);
            } 

            DataContext.Signatures.Add(new Signature
                {
                    Address = model.Address,
                    Country = model.Country,
                    DateSigned = DateTime.Now,
                    Email = model.Email,
                    FullName = model.FullName,
                    RepositoryId = repository.Id,
                    SignatureImage = model.Signature,
                    TelephoneNumber = model.TelephoneNumber,
                    Username = User.Identity.Name
                });

            DataContext.SaveChanges();

            var commitUpdates = await UpdateCommitsFor(repository, User.Identity.Name);

            await Task.WhenAll(commitUpdates.ToArray());

            // TODO: Setup/move validation to EF model?
            // TODO: Support ajax submit?
            // TODO: Wrap in a try/catch
            // TODO: Kill output cache

            Response.RemoveOutputCacheItem(redirectUrl);

            TempData["userSigned"] = new UserSignedNotification("success", User.Identity.Name);
            return Redirect(redirectUrl);
        }
Esempio n. 2
0
        public async Task<ActionResult> Sign(string repoOwner, string repoName)
        {
            var repository = DataContext.Repositories.Where(repoOwner, repoName);
            if (repository == null)
                ViewBag.NotConfigured = true;
            else
                ViewBag.LicenseText = repository.LicenseText;

            var signature = DataContext.Signatures.Where(repoOwner, repoName, User.Identity);
            if (signature != null)
                ViewBag.AlreadySigned = true;

            //TODO: Fix signature when in disabled state

            var user = await GitHubService.GetUser(User.Identity.Name);

            var viewModel = new SignViewModel
                {
                    FullName = user.Name, Email = user.EmailAddress, Date = DateTime.Now, RepoOwner = repoOwner, RepoName = repoName
                };

            return View(viewModel);
        }