public async Task <IActionResult> CategoryAdd(string system, string name)
        {
            _logger.LogDebug($"New category ({name}) is requested");
            var sysrec = await _dbHandler.GetSystemAsync(system);

            var respond = await _dbHandler.AddCategoryAsync(name, sysrec);

            if (respond.MessageType == MessageType.NOK)
            {
                _logger.LogWarning($"{respond.MessageText}");
                GeneralMessage ret = new GeneralMessage();
                ret.Message = respond.MessageText;
                return(BadRequest(ret));
            }
            var data = await _dbHandler.GetCategoryAsync(name, sysrec);

            _logger.LogInformation($"New category ({name}) request is completed");
            return(Ok(data));
        }
Example #2
0
        public async Task <IActionResult> GetUsersBySystem(string name = null, string system = null)
        {
            // Check that input is specified
            if (name == null || system == null)
            {
                return(BadRequest(new GeneralMessage()
                {
                    Message = "Category name and system name must be specified"
                }));
            }

            // Check that either category or system exist
            var checkSys = await _dbHandler.GetSystemAsync(system);

            if (checkSys == null)
            {
                return(BadRequest(new GeneralMessage()
                {
                    Message = "Specified system does not exist"
                }));
            }

            var checkCat = await _dbHandler.GetCategoryAsync(name, checkSys);

            if (checkCat == null)
            {
                return(BadRequest(new GeneralMessage()
                {
                    Message = "Specified category does not exist"
                }));
            }

            // Everything seems fine, do the action
            var response = await _dbHandler.GetUsersAsync(checkCat);

            if (response == null)
            {
                return(BadRequest(new GeneralMessage()
                {
                    Message = "User listing is failed"
                }));
            }

            return(Ok(response));
        }
Example #3
0
        public async Task <IActionResult> CreateTicket(TicketCreationInput info)
        {
            var sys = await _dbHandler.GetSystemAsync(info.System);

            if (sys == null)
            {
                return(BadRequest(new GeneralMessage()
                {
                    Message = "Invalid system name"
                }));
            }

            var cat = await _dbHandler.GetCategoryAsync(info.CategoryName, sys);

            if (cat == null)
            {
                return(BadRequest(new GeneralMessage()
                {
                    Message = "Invalid category"
                }));
            }

            TicketCreationTemplate template = new TicketCreationTemplate();

            template.Category  = cat;
            template.Details   = info.Details;
            template.Reference = info.Reference;
            template.Summary   = info.Summary;
            template.Title     = info.Title;

            if (info.Details == null)
            {
                template.Details = info.Summary;
            }

            // Get user who wants remove user
            var re          = Request;
            var headers     = re.Headers;
            var tokenString = headers["Authorization"];

            var handler = new JwtSecurityTokenHandler();
            var token   = handler.ReadJwtToken(tokenString[0].Split(' ')[1]);

            var claims        = token.Claims;
            var usernameClaim = claims.Where(x => x.Type == ClaimTypes.Name).FirstOrDefault();
            var user          = await _dbHandler.GetUserAsync(usernameClaim.Value);

            template.CreatorUser = user;

            var respond = await _dbHandler.CreateTicketAsync(template);

            if (respond.MessageType == MessageType.NOK)
            {
                return(BadRequest(new GeneralMessage()
                {
                    Message = respond.MessageText
                }));
            }
            return(Ok(new GeneralMessage()
            {
                Message = respond.MessageText
            }));
        }