예제 #1
0
        public IActionResult CreateUser([FromBody] UserForCreationDto user)
        {
            if (user == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var userToAdd = Mapper.Map <Entities.User>(user);

            //If AddUser method false, username exists
            if (!_messangerRepository.AddUser(userToAdd))
            {
                return(BadRequest());
            }

            //If false, there were problem with saving to database
            if (!_messangerRepository.Save())
            {
                return(StatusCode(500, "Server error"));
            }

            return(Ok());
        }
예제 #2
0
        public IActionResult UpdateCase([FromBody] CaseToReturnDto caseToUpdate)
        {
            if (!_messangerRepository.CaseExists(caseToUpdate.CaseId))
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var CaseFromDb = _messangerRepository.GetCase(caseToUpdate.CaseId);

            Mapper.Map(caseToUpdate, CaseFromDb);
            _messangerRepository.UpdateCase(CaseFromDb);

            if (!_messangerRepository.Save())
            {
                return(StatusCode(500, "Problem while handling your request"));
            }

            return(Ok());
        }
예제 #3
0
        public IActionResult SendMessage([FromBody] MessageForCreationDto message)
        {
            if (message == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!_messangerRepository.CaseExists(message.CaseId))
            {
                return(BadRequest());
            }
            var messagetoadd = AutoMapper.Mapper.Map <Entities.Message>(message);

            _messangerRepository.AddMessage(messagetoadd);
            if (!_messangerRepository.Save())
            {
                return(StatusCode(500, "Problem while handling your request."));
            }
            return(Ok());
        }