示例#1
0
        public async Task <IActionResult> CreateUser([FromBody] UserWriteDto _user)
        {
            User user = mapper.Map <User>(_user);

            user.Password = BCrypt.Net.BCrypt.EnhancedHashPassword(user.Password, 11);
            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            return(Ok(mapper.Map <UserReadDTO>(user)));
        }
示例#2
0
        public async Task <IActionResult> CreateProject([FromBody] ProjectWriteDTO _project)
        {
            Project project = _mapper.Map <Project>(_project);

            if (await db.Users.AsNoTracking().FirstOrDefaultAsync(p => p.Id == project.UserId) != null)
            {
                project.Hook = Guid.NewGuid().ToString();

                await db.Projects.AddAsync(project);

                await db.SaveChangesAsync();

                return(Ok());
            }

            return(NotFound());
        }
示例#3
0
        public async Task <IActionResult> OnHook(string hook, [FromBody] JsonElement json)
        {
            if (db.Projects.Where(p => p.Hook == hook).Any())
            {
                if (hookService.VerifyGithubHeaders(Request.Headers))
                {
                    HookIssue hookIssue = hookService.HandleGithubPayload(json);

                    // Mapping values
                    hookIssue.Issue.IssueFrom  = hookIssue.IssueFrom.ToString();
                    hookIssue.Issue.IssueState = hookIssue.IssueState.ToString();

                    if (hookIssue.Existing) // Prexisting issue to be updated
                    {
                        Issue toBeUpdatedIssue = await db.Issues.FirstOrDefaultAsync(p => p.IssueUrl == hookIssue.Issue.IssueUrl);

                        if (toBeUpdatedIssue != null)
                        {
                            toBeUpdatedIssue.IssueFrom     = hookIssue.Issue.IssueFrom;
                            toBeUpdatedIssue.IssueState    = hookIssue.Issue.IssueState;
                            toBeUpdatedIssue.Title         = hookIssue.Issue.Title;
                            toBeUpdatedIssue.Description   = hookIssue.Issue.Description;
                            toBeUpdatedIssue.RepositoryUrl = hookIssue.Issue.RepositoryUrl;
                            toBeUpdatedIssue.IssueUrl      = hookIssue.Issue.IssueUrl;

                            await db.SaveChangesAsync();
                        }
                        else
                        {
                            return(BadRequest());
                        }
                    }
                    else   // A new issue
                    {
                        db.Issues.Add(hookIssue.Issue);
                    }

                    return(Ok());
                }

                return(BadRequest());
            }

            return(NotFound());
        }