Esempio n. 1
0
        public async Task <Response> AddNoteToGroup(AddNoteToGroupBindingModel addNoteToGroupBindingModel)
        {
            var response = new Response();

            var groupExists = await _groupRepository.ExistAsync(x => x.Id == addNoteToGroupBindingModel.GroupId);

            if (!groupExists)
            {
                response.AddError("Group", "Group with given id don't exists");
                return(response);
            }

            var noteModel = new Note();

            noteModel.Group.Id = addNoteToGroupBindingModel.GroupId;
            noteModel.Content  = addNoteToGroupBindingModel.Content;

            var addNoteToGroupResponse = await _noteRepository.AddAsync(noteModel);

            if (addNoteToGroupResponse == null)
            {
                response.AddError("Note", "An error occurred while trying to add note to a group");
                return(response);
            }

            return(response);
        }
Esempio n. 2
0
        public async Task <IActionResult> AddNoteToGroup(AddNoteToGroupBindingModel addNoteToGroupBindingModel)
        {
            var response = await _noteService.AddNoteToGroup(addNoteToGroupBindingModel);

            if (response.ErrorOccurred)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }