public async Task <IActionResult> CreateModBuildAsync(CreateModBuildRequest request)
        {
            var userId = HttpContext.User.FindFirstValue(ClaimTypes.Sid);

            if (!await _modsService.UserIdOwnsModIdAsync(userId, request.ModId))
            {
                return(BadRequest(new GenericResponse
                {
                    Success = false,
                    Message = "Bad ModId for creating a build"
                }));
            }
            var modBuildEntity = await _modBuildsService.CreateModBuildAsync(request);

            if (modBuildEntity == null)
            {
                return(BadRequest(new GenericResponse
                {
                    Success = false,
                    Message = "Unable to create build."
                }));
            }
            return(Ok(new GenericResponse <ModBuildEntity>
            {
                Success = true,
                Message = "Created mod build.",
                Data = modBuildEntity
            }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateModAsync(UpdateModRequest request)
        {
            if (await _srv.GetModByIdAsync(request.Id) == null)
            {
                return(BadRequest(new GenericResponse
                {
                    Success = false,
                    Message = "Mod with that Id does not exist."
                }));
            }
            var userId = HttpContext.User.FindFirstValue(ClaimTypes.Sid);

            if (!await _srv.UserIdOwnsModIdAsync(userId, request.Id))
            {
                return(Unauthorized(new GenericResponse
                {
                    Success = false,
                    Message = "Unauthorized to update mod."
                }));
            }
            var modEntity = await _srv.UpdateModAsync(request);

            return(Ok(new GenericResponse <ModEntity>
            {
                Success = true,
                Message = "Updated mod.",
                Data = modEntity
            }));
        }