public async Task HandleAsync(UpdateNoteCommand command) { var existingNote = await _noteMeContext.Notes .AsTracking() .FirstOrDefaultAsync(x => x.Id == command.Id); var oldNote = new Note { Id = Guid.NewGuid(), ActualNoteId = existingNote.Id, Name = existingNote.Name, Tags = existingNote.Tags, Content = existingNote.Content, Location = existingNote.Location, Status = StatusEnum.Historical, UserId = existingNote.UserId }; await _noteMeContext.AddAsync(oldNote); existingNote.Content = command.Content; existingNote.Name = command.Name; existingNote.Location = NoteMeGeometryFactory.CreatePoint(command.Longitude, command.Latitude); var noteDto = _mapper.Map <NoteDto>(existingNote); _cacheService.Set(noteDto); }
public NoteMapperProfile() { CreateMap <CreateNoteCommand, Note>() .ForMember(x => x.UserId, opt => opt.MapFrom(dst => dst.RequestBy)) .ForMember(x => x.Location, opt => opt.MapFrom(dst => NoteMeGeometryFactory.CreatePoint(dst.Longitude, dst.Latitude))); CreateMap <Note, NoteDto>() .ForMember(x => x.Latitude, opt => opt.MapFrom(dst => dst.Location.Y)) .ForMember(x => x.Longitude, opt => opt.MapFrom(dst => dst.Location.X)); CreateMap <CreateAttachmentCommand, Attachment>(); CreateMap <Attachment, AttachmentDto>(); }