/// <inheritdoc /> /// <summary> /// Добавить пользователя /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task AddUser(User user) { var result = await _repository.GetAsync(u => u.Id == user.Id); if (result == null) { await _repository.CreateAsync(user); if (user.Friends?.Count > 0) { var friends = user.Friends.Select(f => new Friend() { FriendId = f.FriendId, UserId = user.Id }).ToList(); await _friendRepository.CreateAllAsync(friends); } if (user.Tags?.Count > 0) { var tags = user.Tags.Select(t => new Tag() { Name = t, UserId = user.Id }).ToList(); await _tagRepository.CreateAllAsync(tags); } } }
public async Task <string> CreateCommentAsync(string userId, CreateCommentDto createCommentDto) { User user = await _userManager.FindByIdAsync(userId); Guard.Against.NullItem(user, nameof(user)); Post post = await _postRepository.GetByConditionAsync(x => x.Id == createCommentDto.PostId); Guard.Against.NullItem(post, nameof(post)); if (!string.IsNullOrEmpty(createCommentDto.ParentId)) { Comment parentComment = await _commentRepository.GetByConditionAsync(x => x.Id == createCommentDto.ParentId); Guard.Against.NotEqual(parentComment.Post.Id, post.Id); } var comment = _mapper.Map <Comment>(createCommentDto); comment.Author = user; comment.Post = post; await _commentRepository.CreateAsync(comment); return(comment.Id); }
/// <summary> /// Builds the and save. /// </summary> /// <returns></returns> protected async Task <T> PersistSelfAsync(IAsyncRepository repository) { var transactionalRepo = repository as ITransactional; if (transactionalRepo != null) { Debug.Assert(transactionalRepo.HasCurrenTransaction); } if (!AmIPersisted) { ApplicationContext.Logger.Log(LoggingLevel.Debug, "Builder", () => "Persisting {0}", typeof(T)); OnBeforePersistSelf(); await repository.CreateAsync(Target); await repository.SaveChangesAsync(); await repository.ClearAsync(); ApplicationContext.Logger.Log(LoggingLevel.Debug, "Builder", () => "Persisted {0} with Id: {1}", typeof(T), Target.Id); } else { ApplicationContext.Logger.Log(LoggingLevel.Debug, "Builder", () => "Skipping persist of {0} with id {1}", typeof(T), Target.Id); } return(Target); }
public async Task <bool> CreateLinkAsync(LinkViewModel lvm, string userId, CancellationToken cancellationToken = default) { var certificate = await _certificateRepository.GetCertificateIncludeLinksAsync(lvm.CertificateId, userId, cancellationToken); if (certificate != null) { // Check the limit (maximum 5). if (certificate.Links.Count >= 5) { return(true); } await _linkRepository.CreateAsync(new Link(lvm.Url, lvm.CertificateId), cancellationToken); await _cacheService.SetItemAsync(lvm.CertificateId, userId); return(true); } return(false); }
public async Task <Group> CreateGroupAsync(string name, string username) { var group = new Group(name, username); await _repository.CreateAsync(group); return(group); }
public async Task <User> CreateAsync(string username, string email, string password) { var user = new User(username, email, password); user.HashedPassword = _hasher.Hash(user, password); return(await _repository.CreateAsync(user)); }
public async Task <string> CreateCategoryAsync(CreateCategoryDto createCategoryDto) { var category = _mapper.Map <Category>(createCategoryDto); await _categoryRepository.CreateAsync(category); return(category.Id); }
public virtual async Task <DTO> CreateAsync(CreateDTO model) { var validationResult = await createValidator.ValidateAsync(model); if (!validationResult.IsValid) { throw new Exceptions.ValidationException(validationResult); } return(mapper.Map <DTO>(await repository.CreateAsync(mapper.Map <Domain>(model)))); }
public async Task AddOrUpdateSyncData(SyncDao data) { var listData = await _repository.FetchAsync(); if (listData == null || listData.Count() == 0) { await _repository.CreateAsync(data); } else { await _repository.UpdateAsync(data); } }
public async Task <string> CreatePostAsync(string userId, CreatePostDto createPostDto) { User user = await _userManager.FindByIdAsync(userId); Guard.Against.NullItem(user, nameof(user)); var post = _mapper.Map <Post>(createPostDto); post.AuthorId = user.Id; post.ContentType = "application/text"; await _postRepository.CreateAsync(post); return(post.Id); }
public async Task <CategoryDto> Handle(Request request, CancellationToken cancellationToken) { var category = new Category(); _mapper.Map(request as CategoryDto, category); try { var result = await _repository.CreateAsync(category); return(_mapper.Map <CategoryDto>(category)); } catch (Exception) { throw new RestException(HttpStatusCode.BadRequest, new { Error = "Unable to create Category" }); } }
/// <summary> /// Вставить запись /// </summary> /// <param name="entity"></param> /// <returns></returns> public virtual async Task CreateAsync(T entity) { await Repository.CreateAsync(entity); }
public virtual async Task <TEntity> CreateAsync(TEntity entity) { var result = await Repository.CreateAsync(entity); return(result); }
public async Task <IActionResult> Create([FromBody] TResource item) { TEntity entity = await _repository.CreateAsync(Mapper.Map <TEntity> (item)); return(Ok(Mapper.Map <TResource> (entity))); }
public async Task <Note> CreateNoteAsync(string name, long groupId, string username) { var note = new Note(name, groupId, username); return(await _repository.CreateAsync(note)); }