public async Task <IActionResult> PostClub([FromBody] Club club) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } repo.Add(club); await repo.SaveAllChangesAsync(); return(CreatedAtAction("GetClub", new { id = club.Id }, club)); }
public async Task <IActionResult> PostMember([FromBody] Person member) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } repo.Add(member); await repo.SaveAllChangesAsync(); return(CreatedAtAction("GetMember", new { id = member.Id }, member)); }
public async Task <ActionResult> Add([FromHeader] string Authentication, [FromQuery] string userId, [FromQuery] string groupId) { if (SessionManager.GetSessionState(Authentication) != SessionManager.SessionState.Authorized) { return(Unauthorized()); } SessionInfo sessionInfo = SessionManager.GetSessionInfo(Authentication); if (sessionInfo == null) { return(Unauthorized()); } int userIdInt = 0; int groupIdInt = 0; if (!int.TryParse(userId, out userIdInt) || !int.TryParse(userId, out groupIdInt)) { return(BadRequest("Bad id")); } using (UnitOfWork uow = new UnitOfWork()) { MembershipRepository membershipRepo = new MembershipRepository(uow); MembershipDTO membership = await membershipRepo.GetByUserAndGroupId(userIdInt, groupIdInt); if (membership != null) { if (membership.Status == 0 && userIdInt == sessionInfo.UserId) { membership.Status = 1; await membershipRepo.Update(membership); } else { return(Ok()); } } else { membership = new MembershipDTO { UserId = userIdInt, GroupId = groupIdInt, Status = 0 }; membership.Id = await membershipRepo.Add(membership); } uow.Commit(); return(Ok(membership)); } }
public async Task <ActionResult> Add([FromHeader] string Authentication, [FromBody] GroupDTO group) { if (SessionManager.GetSessionState(Authentication) != SessionManager.SessionState.Authorized) { return(Unauthorized()); } SessionInfo sessionInfo = SessionManager.GetSessionInfo(Authentication); if (sessionInfo == null) { return(Unauthorized()); } if (string.IsNullOrEmpty(group.Name) || string.IsNullOrEmpty(group.DefaultCurrency) || !Currencies.CurrenciesList.Contains(group.DefaultCurrency)) { return(BadRequest()); } group.CreatedDate = DateTime.Now; using (UnitOfWork uow = new UnitOfWork()) { GroupsRepository groupsRepository = new GroupsRepository(uow); group.Id = await groupsRepository.Add(group); MembershipDTO membership = new MembershipDTO { UserId = sessionInfo.UserId, GroupId = group.Id, Status = 3 }; MembershipRepository membershipRepository = new MembershipRepository(uow); await membershipRepository.Add(membership); uow.Commit(); } return(Ok()); }