Exemple #1
0
        public ActionResult <ForumMessageDTO> CreateForumMessage([FromHeader] string key, [FromBody] ForumMessageCreateDTO newForumMessage)
        {
            if (!_authorizationService.AuthorizeUser(key))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!"));
            }

            var newmess = newForumMessage;

            if (newmess.ForumID == 0 || newmess.Body == "" || _forumMessageService.GetForumMessagesByForumID(newmess.ForumID) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Unvalid message! Check your data!"));
            }
            if (_forumService.GetForumByID(newmess.ForumID).IsOpen == false)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Forum is closed! You can not send message!"));
            }

            try
            {
                var created = _forumMessageService.CreateForumMessage(newForumMessage);

                return(created);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error creating new forum message: " + ex.Message);

                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemple #2
0
        public ActionResult <Customer> GetCustomer(string id)
        {
            var customer = _customerRepository.GetCustomerById(id);

            if (customer == null)
            {
                var error = ErrorMessages.CustomerNotFound;
                _logger.LogError(error);
                return(NotFound(error));
            }

            return(Ok(customer));
        }
Exemple #3
0
        public ActionResult <RatingTypeDTO> CreateRatingType([FromHeader] string key, [FromBody] RatingTypeCreationDTO type)
        {
            if (!_authService.Authorize(key))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!"));
            }

            try
            {
                var createdType = _ratingTypeService.CreateRatingType(type);

                string location = linkGenerator.GetPathByAction("GetRatingTypeByID", "RatingType", new { ratingTypeID = createdType.RatingTypeID });

                return(Created(location, createdType));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error creating new type of raiting: " + ex.Message);

                return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating new type of rating!"));
            }
        }
Exemple #4
0
        public ActionResult <BlockDTO> Block([FromHeader] string key, [FromBody] BlockCreationDTO block, int blockerID, int blockedID)
        {
            if (!_authService.Authorize(key))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!"));
            }

            try
            {
                var createdType = _blockingService.Block(block, blockerID, blockedID);


                //string location = linkGenerator.GetPathByAction("GetBlockByID", "Block", new { BlockID = createdType.BlockID });

                return(StatusCode(StatusCodes.Status201Created, "You have successfully blocked user"));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error creating new block: " + ex.Message);

                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
        public ActionResult <ForumDTO> CreateForum([FromHeader] string key, [FromBody] ForumDTO newForum)
        {
            if (!_authorizationService.AuthorizeUser(key))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!"));
            }

            try
            {
                var created = _forumService.CreateForum(newForum);


                string location = linkGenerator.GetPathByAction("GetForumByID", "Forum", new { forumID = created.ForumID });

                return(Created(location, created));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error creating new forum: " + ex.Message);

                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemple #6
0
 public async Task InvokeAsync(HttpContext httpContext)
 {
     try
     {
         await _next(httpContext);
     }
     catch (Exception ex)
     {
         StringBuilder logText    = new StringBuilder();
         var           controller = httpContext.GetRouteValue("controller");
         var           action     = httpContext.GetRouteValue("action");
         logText.Append("Message: " + ex.Message + "\n");
         logText.Append("Controller: " + controller + "\n");
         logText.Append("Action: " + action + "\n");
         logText.Append("Source: " + ex.Source + "\n");
         logText.Append("TargetSite: " + ex.TargetSite + "\n");
         logText.Append("StackTrace: " + ex.StackTrace);
         await _logger.LogError(logText.ToString());
         await HandleExceptionAsync(httpContext, ex);
     }
 }