public async Task <ActionResult> UpdateAsync(Guid id, MemberDetailsDto dto) { dto.Id = id; await _memberService.UpdateAsync(dto); return(NoContent()); }
public async Task <MemberDetailsDto> UpdateMemberDetails(MemberDetailsDto dto) { if (dto == null) { throw new NullReferenceException("You must send member details."); } if (!ModelState.IsValid) { throw new ArgumentException("State isn't valid"); } short userId = Convert.ToInt16(_httpContext.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); Member member = await _memberService.GetMember(userId); if (member == null) { throw new UnauthorizedAccessException("User not found"); } Member sendedMember = _mapper.Map <Member>(dto); var updatedMember = await _memberService.UpdateMember(userId, sendedMember); var response = _mapper.Map <MemberDetailsDto>(updatedMember); return(response); }
public MemberDetailsDto MapToMemberDetails(IMember member) { var memberDetails = new MemberDetailsDto() { Name = member.Name, Email = member.Email, Phone = member.GetValue <string>(MemberProperty.Phone), MembershipType = member.GetValue <MembershipTypeEnum>(MemberProperty.membershipType), SwimSubs1 = member.GetValue <string>(MemberProperty.swimSubs1), SwimSubs2 = member.GetValue <string>(MemberProperty.swimSubs2), EnglandAthleticsMembership = member.GetValue <bool>(MemberProperty.EnglandAthleticsMembership), OpenWaterIndemnityAcceptance = member.GetValue <bool>(MemberProperty.OpenWaterIndemnityAcceptance), Volunteering = member.GetValue <bool>(MemberProperty.Volunteering), MembershipExpiry = member.GetValue <DateTime>(MemberProperty.MembershipExpiry), SwimAuthNumber = member.GetValue <int?>(MemberProperty.SwimAuthNumber), TrainingCredits = member.GetValue <int>(MemberProperty.TrainingCredits), BtfNumber = member.GetValue <string>(MemberProperty.BTFNumber), Gender = member.GetValue <GenderEnum>(MemberProperty.Gender).ToString(), DateOfBirth = member.GetValue <DateTime>(MemberProperty.DateOfBirth), Address1 = member.GetValue <string>(MemberProperty.Address1), City = member.GetValue <string>(MemberProperty.City), Postcode = member.GetValue <string>(MemberProperty.Postcode), MedicalConditions = member.GetValue <string>(MemberProperty.MedicalConditions), EmergencyContactName = member.GetValue <string>(MemberProperty.EmergencyContactName), EmergencyContactNumber = member.GetValue <string>(MemberProperty.EmergencyContactNumber), }; return(memberDetails); }
public async Task AddAsync(MemberDetailsDto dto) { dto.Id = Guid.NewGuid(); var member = new Member { Id = dto.Id, Name = dto.Name, Description = dto.Description }; await _memberRepository.AddAsync(member); }
public async Task UpdateAsync(MemberDetailsDto dto) { var member = await _memberRepository.GetAsync(dto.Id); if (member is null) { throw new MemberNotFoundException(dto.Id); } member.Id = dto.Id; member.Name = dto.Name; member.Description = dto.Description; await _memberRepository.UpdateAsync(member); }
public async Task <ActionResult <MemberDetailsDto> > GetUser(short Id) { short userId = Convert.ToInt16(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); if (Id != userId) { return(Unauthorized("You don't have access to other member information.")); } Member user = await _memberService.GetMember(userId); if (user == null) { return(Unauthorized("You don't have an access")); } MemberDetailsDto response = _mapper.Map <MemberDetailsDto>(user); return(Ok(response)); }
public async Task <ActionResult> AddAsync(MemberDetailsDto dto) { await _memberService.AddAsync(dto); return(CreatedAtAction(nameof(Get), new { id = dto.Id }, null)); }