public async Task AcceptInvitation(int groupId, string invitation, string userId) { var group = await _repository.GetGroup(groupId); if (group.Members.Any(m => m.UserId == userId && invitation == m.Guid && m.IsActive)) { throw new UserAlreadyJoinedException(); } var updatedGroupMember = group.Members.FirstOrDefault(g => g.UserId == userId)?.ActivateMember(); if (updatedGroupMember == null) { throw new UserNotFoundException(); } await _repository.UpdateGroupMember(updatedGroupMember); }
public void BeforeSplitBill(GroupKey g, double amount) { var group = _groupsRepository.GetGroup(g); var members = group.Users; members.Add(g.PhoneNumber); var no_members = group.Users.Count; float to_pay = (float)amount / (float)no_members; int not_fully_paying = 0; string names = null; foreach (string user_no in members) { var us = _userRepository.GetUserByPhoneNumber(user_no); var u = new UserLeftAmount(); u.User = us; if (us.Amount < to_pay) { not_fully_paying++; names += us.FirstName + " " + us.LastName + ", "; } else { u.Amount = to_pay; } } if (not_fully_paying != 0) { throw new Exception("Users: " + names + "don't have enough money!"); } //return paying_list; }
public async Task <IActionResult> DeleteGroups([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var groups = await _groupsRepository.GetGroup(id); if (groups == null) { return(NotFound()); } await _groupsRepository.DeleteGroup(groups); await _groupsRepository.Save(); return(Ok(groups)); }