Example #1
0
 public IActionResult Authenticate([FromBody] AuthenticateModel model)
 {
     try
     {
         var user = _userRepository.Authenticate(model.Username, model.Password);
         if (user == null)
         {
             return(BadRequest(new { message = "Username or password is incorrect" }));
         }
         return(Ok(user));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Something went wrong inside Authenticate action: {ex.Message}");
         return(StatusCode(500, "Internal server error"));
     }
 }
        public async Task <IActionResult> CreateTask([FromBody] CreateTaskDto taskDto)
        {
            try
            {
                if (taskDto == null)
                {
                    _logger.LogError("Object sent from client is null.");
                    return(BadRequest("Owner object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid object sent from client.");
                    return(BadRequest("Invalid model object"));
                }
                await _taskRepository.CreateAsync(new TaskEntity
                {
                    PartitionKey = taskDto.ProjectId,
                    RowKey       = Guid.NewGuid().ToString().Substring(1, 7),
                    Name         = taskDto.Name,
                    Description  = taskDto.Description
                });

                return(Created("", taskDto));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside task Create action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <IActionResult> CreateProject([FromBody] CreateUpdateProjectDto createProjectDto)
        {
            try
            {
                if (createProjectDto == null)
                {
                    _logger.LogError("Object sent from client is null.");
                    return(BadRequest("Owner object is null"));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                await _projectRepository.CreateAsync(new ProjectEntity
                {
                    PartitionKey = createProjectDto.Name,
                    RowKey       = Guid.NewGuid().ToString(),
                    Description  = createProjectDto.Description,
                    Code         = createProjectDto.Code,
                });

                return(Created("", createProjectDto));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside project Create action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Example #4
0
        public IActionResult GetAllOwners()
        {
            try
            {
                var owner = _repository.Owner.GetAllOwners();
                // var owner = new string[] { "value1", "value2" };

                _logger.LogInfo($"Returned all owners from databse.");

                return(Ok(owner));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside GetAllOwners action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }