コード例 #1
0
ファイル: NoteCreator.cs プロジェクト: hadre1213/pz-project
        public NoteEntity CreateNewNoteForGroup(CreateNoteRequest request, int groupId, int userId)
        {
            var noteModel  = CreateNoteModel(request, userId);
            var noteEntity = MapModelToEntity(noteModel);

            return(Create(noteEntity, groupId, userId));
        }
コード例 #2
0
        /// <summary>Handles a request</summary>
        /// <param name="request">The request</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>Response from the request</returns>
        public async Task <Result <NoteDto> > Handle(CreateNoteRequest request, CancellationToken cancellationToken)
        {
            var note   = _mapper.Map <INote>(request.Note);
            var result = await _noteRepository.CreateAsync(note);

            return(result.ToResult(_ => _mapper.Map <NoteDto>(result.ValueOrDefault)));
        }
コード例 #3
0
        public void CreateNoteForGroup(CreateNoteRequest request, int groupId, int issuerId)
        {
            var user  = GetUserForId(issuerId);
            var group = GetGroupForId(groupId);

            _notesCreator.CreateNewNoteForGroup(request, group.GroupId, user.UserId);
        }
コード例 #4
0
        public async Task CreateNoteAsync()
        {
            Mock <Grafeas.GrafeasClient> mockGrpcClient  = new Mock <Grafeas.GrafeasClient>(MockBehavior.Strict);
            CreateNoteRequest            expectedRequest = new CreateNoteRequest
            {
                ParentAsProjectName = new ProjectName("[PROJECT]"),
                NoteId = "noteId2129224840",
                Note   = new Note(),
            };
            Note expectedResponse = new Note
            {
                NoteName         = new NoteName("[PROJECT]", "[NOTE]"),
                ShortDescription = "shortDescription-235369287",
                LongDescription  = "longDescription-1747792199",
            };

            mockGrpcClient.Setup(x => x.CreateNoteAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Note>(Task.FromResult(expectedResponse), null, null, null, null));
            GrafeasClient client   = new GrafeasClientImpl(mockGrpcClient.Object, null);
            ProjectName   parent   = new ProjectName("[PROJECT]");
            string        noteId   = "noteId2129224840";
            Note          note     = new Note();
            Note          response = await client.CreateNoteAsync(parent, noteId, note);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
コード例 #5
0
        public IActionResult Create([FromBody] CreateNoteRequest noteRequest)
        {
            if (noteRequest == null)
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(noteRequest.Id))
            {
                noteRequest.Id = Guid.NewGuid().ToString();
            }

            var note = new Note {
                Id = noteRequest.Id, Tag = noteRequest.Tag, Title = noteRequest.Title, Post = noteRequest.Post, UserId = HttpContext.GetUserId()
            };

            this._noteService.Create(note);

            var baseUrl     = HttpContext.Request.Scheme + "://" + HttpContext.Request.Host.ToUriComponent();
            var locationUri = baseUrl + "/" + ApiRoutes.Notes.Get.Replace("{noteId}", noteRequest.Id);

            var response = new NoteResponse {
                Id = note.Id, Tag = note.Tag, Title = note.Title, Post = note.Post
            };

            return(Created(locationUri, response));
        }
コード例 #6
0
        public async Task <Note> PostNewNoteAsync(CreateNoteRequest request)
        {
            var dbNote = new NoteDb
            {
                Id          = Guid.NewGuid(),
                Description = request.Description,
                CreatedAt   = request.CreatedAt.Value,
                TargetId    = request.TargetId.Value,
                TargetType  = request.TargetType.Value,
                Author      = new AuthorDetails
                {
                    Email    = request.Author?.Email,
                    FullName = request.Author?.FullName
                },
                Categorisation = new Categorisation
                {
                    Description = request.Categorisation?.Description,
                    Category    = request.Categorisation?.Category,
                    SubCategory = request.Categorisation?.SubCategory
                }
            };

            _logger.LogDebug($"Saving a new note for targetId: {dbNote.TargetId}, targetType: {Enum.GetName(typeof(TargetType), dbNote.TargetType)}");
            await _dynamoDbContext.SaveAsync(dbNote).ConfigureAwait(false);

            return(dbNote.ToDomain());
        }
コード例 #7
0
ファイル: NoteServicer.cs プロジェクト: felixwan-git/Kadder
 public Task <CreateNoteResponse> CreateAsync(CreateNoteRequest request)
 {
     return(Task.FromResult(new CreateNoteResponse()
     {
         Title = request.Title,
         Status = true
     }));
 }
コード例 #8
0
        public async Task <IActionResult> AddNoteAsync(CreateNoteRequest model,
                                                       CancellationToken token)
        {
            var command = new CreateNoteCommand(model.UserId, model.Text, User.GetIdClaim());
            await _commandBus.DispatchAsync(command, token);

            return(Ok(User.Identity.Name));
        }
コード例 #9
0
        public async Task <int> CreateNoteAsync(string zoneName, CreateNoteRequest req)
        {
            if (string.IsNullOrEmpty(zoneName))
            {
                throw new Client.Exception.ANSClientValidationException("Invalid zone name");
            }

            return((await this.Client.PostAsync <Note>($"/safedns/v1/zones/{zoneName}/notes", req)).ID);
        }
コード例 #10
0
ファイル: NoteService.cs プロジェクト: tklonowski/Portfolio
        private Note Map(CreateNoteRequest noteRequest)
        {
            Note note = new Note();

            note.Description = noteRequest.Description;
            note.Title       = noteRequest.Title;

            return(note);
        }
コード例 #11
0
ファイル: NoteServicer.cs プロジェクト: felixwan-git/Kadder
    public Task <CreateNoteResponse> CreateNoteAsync(CreateNoteRequest request)
    {
        Console.WriteLine($"Receive create note request[Title: {request.Title} -> Content: {request.Content}]");

        return(Task.FromResult(new CreateNoteResponse()
        {
            Title = request.Title, StatusCode = true
        }));
    }
コード例 #12
0
 internal static NoteEntity ToEntity(this CreateNoteRequest request)
 {
     return(request == null ? null : new NoteEntity
     {
         Name = request.Name,
         Description = request.Description,
         Note = request.Note
     });
 }
コード例 #13
0
ファイル: NoteService.cs プロジェクト: artma-gronsky/megaNote
        public async Task <Guid> Create(CreateNoteRequest request)
        {
            var note = new Note(request.FirstName, request.LastName, request.Phone, request.Email, request.AdditionalInfo);

            _noteRepository.Create(note);

            await _noteRepository.SaveChangesAsync();

            return(note.Id);
        }
コード例 #14
0
        public void RequestShouldErrorWithNullTargetId()
        {
            var model = new CreateNoteRequest()
            {
                TargetId = null
            };
            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(x => x.TargetId);
        }
コード例 #15
0
        public void RequestShouldErrorWithInvalidValidTargetType(int?val)
        {
            var model = new CreateNoteRequest()
            {
                TargetType = (TargetType?)val
            };
            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(x => x.TargetType);
        }
コード例 #16
0
        public void RequestShouldErrorWithNullOrEmptyDescription(string description)
        {
            var model = new CreateNoteRequest()
            {
                Description = description
            };
            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(x => x.Description);
        }
コード例 #17
0
        public void RequestShouldErrorWithNullCreatedAt()
        {
            var model = new CreateNoteRequest()
            {
                CreatedAt = null
            };
            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(x => x.CreatedAt);
        }
コード例 #18
0
        public void RequestShouldNotErrorWithValidTargetType(TargetType tt)
        {
            var model = new CreateNoteRequest()
            {
                TargetType = tt
            };
            var result = _sut.TestValidate(model);

            result.ShouldNotHaveValidationErrorFor(x => x.TargetType);
        }
コード例 #19
0
ファイル: NoteManager.cs プロジェクト: Johnny0121/Mango
        public async Task <NoteResponse> CreateAsync(CreateNoteRequest request)
        {
            NoteEntity _CreatedEntity = await __NoteRepository.CreateAsync(request.ToEntity());

            return(_CreatedEntity.ToResponse() ?? new NoteResponse
            {
                Success = false,
                ErrorMessage = $"{GlobalConstants.ERROR_ACTION_PREFIX} create {ENTITY_NAME}."
            });
        }
コード例 #20
0
ファイル: NoteCreator.cs プロジェクト: hadre1213/pz-project
        private CreateNoteModel CreateNoteModel(CreateNoteRequest request, int userId)
        {
            var noteModel = new CreateNoteModel
            {
                CreatorId       = userId,
                NoteName        = request.NoteName,
                NoteDescription = request.NoteDescription
            };

            return(noteModel);
        }
コード例 #21
0
        public void RequestShouldNotErrorWithValidDescription()
        {
            string description = "This description is fine.";
            var    model       = new CreateNoteRequest()
            {
                Description = description
            };
            var result = _sut.TestValidate(model);

            result.ShouldNotHaveValidationErrorFor(x => x.Description);
        }
コード例 #22
0
        public void RequestShouldErrorWithAuthorError()
        {
            var model = new CreateNoteRequest()
            {
                Author = new AuthorDetails()
                {
                    Email = "dflgkj"
                }
            };
            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(x => x.Author.Email);
        }
コード例 #23
0
        /// <summary>
        /// Creates a note in the <c>CRM</c>
        /// </summary>
        /// <param name="crm">
        /// The <see cref="AgileCRM"/> instance to be used.
        /// </param>
        /// <param name="subject">
        /// The subject of the note.
        /// </param>
        /// <param name="description">
        /// The description of the note.
        /// </param>
        /// <param name="contactIds">
        /// The related contact identifiers.
        /// </param>
        /// <returns>
        /// The created note
        /// </returns>
        public static async Task <Note> CreateContactNoteAsync(AgileCRM crm, string subject, string description, List <long> contactIds)
        {
            var createNoteRequest = new CreateNoteRequest()
            {
                Subject     = subject,
                Description = description,
                ContactIds  = contactIds,
            };

            var response = await crm.RequestAsync($"notes", HttpMethod.Post, JsonConvert.SerializeObject(createNoteRequest)).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <Note>(response));
        }
コード例 #24
0
        public IActionResult Create(string loginToken, [FromBody] CreateNoteRequest request)
        {
            try
            {
                _noteService.CreateNote(loginToken, request.model);
            }
            catch (Exception e)
            {
                LogService.Info <NoteController>(e.StackTrace);
                return(BadRequest(e.Message));
            }

            return(Ok("Create Note Successfully."));
        }
コード例 #25
0
        public IActionResult CreateNoteForGroup([FromBody] CreateNoteRequest request, int id)
        {
            try
            {
                var userId = this.GetUserId();
                _noteOperationsHandler.CreateNoteForGroup(request, id, userId);

                return(Created(string.Empty, null));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #26
0
        /// <summary>
        /// Add a public/private note to a ticket.
        ///
        /// c.f. https://developers.freshdesk.com/api/#add_note_to_a_ticket
        /// </summary>
        ///
        /// <param name="ticketId">
        /// The ticket to add the reply to.
        /// </param>
        ///
        /// <param name="request">
        /// Defines the set of properties to set on the note.
        /// </param>
        ///
        /// <param name="cancellationToken"></param>
        ///
        /// <returns>The full conversation entry</returns>
        public async Task <ConversationEntry> CreateNoteAsync(
            long ticketId,
            CreateNoteRequest request,
            CancellationToken cancellationToken = default)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request), "Request must not be null");
            }

            return(await _client
                   .ApiOperationAsync <ConversationEntry>(HttpMethod.Post, $"/api/v2/tickets/{ticketId}/notes", request, cancellationToken)
                   .ConfigureAwait(false));
        }
コード例 #27
0
        public async Task <IActionResult> CreateNote([FromBody] CreateNoteRequest req)
        {
            var users = await _context.Users.Include(u => u.Notes).ToArrayAsync();

            foreach (var u in users)
            {
                if (u.Id.Equals(req.user.Id))
                {
                    u.Notes.Add(req.note);
                    await _context.SaveChangesAsync();

                    return(Ok("note creaed successfuly"));
                }
            }

            return(BadRequest("User not found at creating new note"));
        }
コード例 #28
0
        public void RequestShouldErrorWithDescriptionTooLong()
        {
            var    msgToRepeat = "This description is to long. ";
            string description = "";

            while (description.Length <= 500)
            {
                description += msgToRepeat;
            }
            var model = new CreateNoteRequest()
            {
                Description = description
            };
            var result = _sut.TestValidate(model);

            result.ShouldHaveValidationErrorFor(x => x.Description);
        }
コード例 #29
0
        public async Task CreateZoneNoteAsync_ExpectedResult()
        {
            CreateNoteRequest req = new CreateNoteRequest()
            {
                Notes = "test note"
            };

            IANSSafeDNSClient client = Substitute.For <IANSSafeDNSClient>();

            client.PostAsync <Note>("/safedns/v1/zones/example.com/notes", req).Returns(new Note()
            {
                ID = 123
            });

            var ops = new ZoneNoteOperations <Note>(client);
            int id  = await ops.CreateNoteAsync("example.com", req);

            Assert.AreEqual(123, id);
        }
コード例 #30
0
        public void CreateNote2()
        {
            Mock <Grafeas.GrafeasClient> mockGrpcClient = new Mock <Grafeas.GrafeasClient>(MockBehavior.Strict);
            CreateNoteRequest            request        = new CreateNoteRequest
            {
                ParentAsProjectName = new ProjectName("[PROJECT]"),
                NoteId = "noteId2129224840",
                Note   = new Note(),
            };
            Note expectedResponse = new Note
            {
                NoteName         = new NoteName("[PROJECT]", "[NOTE]"),
                ShortDescription = "shortDescription-235369287",
                LongDescription  = "longDescription-1747792199",
            };

            mockGrpcClient.Setup(x => x.CreateNote(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            GrafeasClient client   = new GrafeasClientImpl(mockGrpcClient.Object, null);
            Note          response = client.CreateNote(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }