示例#1
0
        public async Task CreateChat([FromBody] SaveChatResource newChat)
        {
            var validator = new SaveChatResourceValidator();
            var result    = await validator.ValidateAsync(newChat);

            if (!result.IsValid)
            {
                throw new Exception(result.Errors.ToString());
            }
            var chatToCreate = _mapper.Map <SaveChatResource, Chat>(newChat);
            await _chatService.CreateChat(chatToCreate);
        }
示例#2
0
        public async Task UpdateChat([FromBody] SaveChatResource chat, int id)
        {
            var validator = new SaveChatResourceValidator();
            var result    = await validator.ValidateAsync(chat);

            if (id == 0 || !result.IsValid)
            {
                throw new Exception(result.Errors.ToString());
            }
            var chatToBeUpdate = await _chatService.GetChatById(id);

            if (chatToBeUpdate == null)
            {
                throw new Exception("Chat bestaat niet");
            }
            var _chat = _mapper.Map <SaveChatResource, Chat>(chat);
            await _chatService.UpdateChat(chatToBeUpdate, _chat);
        }