public async Task <int> Handle(CreateCommunityCommand request, CancellationToken cancellationToken) { var community = new Community(request.Name, request.User, request.Description); await _communityRepository.Add(community); return(community.Id); }
public void Handle(CreateProduct command) { var product = new Product(command.ProductId, command.Name, command.Count); _domainRepository.Add(product); _unitOfWork.Commit(); }
/// <summary> /// Adss the group information to the underlying group repository /// </summary> /// <param name="model"></param> private void AddGroup(GroupCreationBlockViewModel model) { var validatedInputs = ValidateGroupInputs(model.Name, model.Description); if (validatedInputs) { try { //Add the group and persist the group name in temp data to be used in the success message var group = new Social.Models.Groups.Community(model.Name, model.Description); var newGroup = _communityRepository.Add(group); if (model.IsModerated) { _moderationRepository.AddWorkflow(newGroup); } var message = "Your group: " + model.Name + " was added successfully!"; AddMessage(MessageKey, new MessageViewModel(message, SuccessMessage)); } catch (SocialRepositoryException ex) { //Persist the exception message in temp data to be used in the error message AddMessage(MessageKey, new MessageViewModel(ex.Message, ErrorMessage)); } } else { //Persist the exception message in temp data to be used in the error message var message = "Group name and description cannot be empty"; AddMessage(MessageKey, new MessageViewModel(message, ErrorMessage)); } }
public async Task <Community> Create(string name, bool showCurrentUser, string supportEmail) { var creator = _authService.GetCurrentUser(); var communityId = _context.Communities.Document().Id; var community = new Community { Id = communityId, Name = name, ShowCurrentUser = showCurrentUser, SupportEmail = supportEmail }; var membership = new CommunityMembership { Name = creator.Username, Role = CommunityRole.CommunityAdmin, CommunityId = communityId, UserId = creator.Id }; await _context.RunTransactionAsync(transaction => { _communityRepository.Add(community, transaction); _membershipRepository.Add(membership, transaction); }); return(community); }
public async Task <IActionResult> LikeUser(int id, int recipientId) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var like = await _repo.GetLike(id, recipientId); if (like != null) { return(BadRequest("You already liked this user")); } if (await _repo.GetUser(recipientId) == null) { return(NotFound()); } like = new Like { LikerId = id, LikeeId = recipientId }; _repo.Add <Like>(like); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to like user.")); }
public virtual void Handle(Register command) { if (_DomainRepository.Find <Account>(a => a.UserName == command.UserName) != null) { throw new DomainException(ErrorCode.UsernameAlreadyExists, $"Username {command.UserName} exists!"); } var account = new Account(command.UserName, command.Password, command.Email); _DomainRepository.Add(account); _UnitOfWork.Commit(); _CommandContext.Reply = account.ID; }