Exemple #1
0
        public async Task <IActionResult> Edit(string id, [Bind("Id,Workflow,Context")] HookViewModel hookViewModel)
        {
            if (id != hookViewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var hook = hookViewModel.ToEntity();
                try
                {
                    _context.Update(hook);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HookExists(hook.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.isEdit = true;
            ViewBag.types  = Constants.allowedTypes;
            return(View("CreateEdit", hookViewModel));
        }
Exemple #2
0
        public async Task <IActionResult> Complete(HookViewModel model)
        {
            if (ModelState.IsValid)
            {
                List <Shared.WebHook> webHooks = null;
                var webHooksFilePath           = Path.Combine(_hostingEnvironment.ContentRootPath, "webhooks.json");

                if (System.IO.File.Exists(webHooksFilePath))
                {
                    webHooks = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Shared.WebHook> >(
                        System.IO.File.ReadAllText(webHooksFilePath));
                }
                else
                {
                    webHooks = new List <Shared.WebHook>();
                }

                webHooks.Add(new Shared.WebHook()
                {
                    PersonalAccessToken = model.PersonalAccessToken,
                    RemoteUrl           = model.RepositoryUrl,
                    Secret = model.Secret
                });

                System.IO.File.WriteAllText(webHooksFilePath, Newtonsoft.Json.JsonConvert.SerializeObject(webHooks));

                return(RedirectToAction(nameof(ContentController.Index), "Content"));
            }

            return(View("Hook"));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,Workflow,Context")] HookViewModel hookViewModel)
        {
            if (ModelState.IsValid)
            {
                var hook = hookViewModel.ToEntity();
                _context.Add(hook);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.types = Constants.allowedTypes;
            return(View("CreateEdit", hookViewModel));
        }
Exemple #4
0
 public static Hook ToEntity(this HookViewModel hookViewModel)
 {
     return(new Hook
     {
         Id = hookViewModel.Id,
         Workflow = hookViewModel.Workflow,
         Context = hookViewModel.Context?.Select(context => new HookContext
         {
             Field = context.Field,
             Description = context.Description,
             IsPrefetchToken = context.IsPrefetchToken,
             Optionality = context.IsRequired ? ContextOptionality.REQUIRED : ContextOptionality.OPTIONAL,
             Type = context.IsArrayType ? Type.GetType(context.Type).MakeArrayType() : Type.GetType(context.Type)
         }).ToList()
     });
 }