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 async Task CreateAsync <TCommand, TEntity, TDto>(TCommand command) where TCommand : ICommandProvider where TEntity : IIdProvider where TDto : IIdProvider { var entity = _mapper.Map <TEntity>(command); await _context.AddAsync(entity); var dto = _mapper.Map <TDto>(entity); _cacheService.Set(dto); }
public async Task HandleAsync(UserRegisterCommand command) { var user = _mapper.Map <User>(command); var isExists = await _context.Users.AnyAsync(x => x.Email == command.Email); if (isExists) { throw new ServerException(ErrorCodes.UserAlreadyExists); } user.Salt = _encrypterService.GetSalt(); user.Hash = _encrypterService.GetHash(command.Password, user.Salt); await _context.AddAsync(user); var created = _mapper.Map <UserDto>(user); _memoryCacheService.Set(created); }