public async Task <IResponse> DeleteMemberContactAsync(int memberContactId) { var response = new Response(); try { var memberContactFromDB = await MemberContactRepository.GetSingleMemberContactByIDAsync(memberContactId); if (memberContactFromDB == null) { response.Message = ResponseMessageDisplay.NotFound; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(MemberMessageDisplay.MemberContactNotFoundMessage)); } else { await MemberContactRepository.DeleteMemberContactAsync(memberContactFromDB); response.Message = ResponseMessageDisplay.Success; } } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <ISingleResponse <vmMemberContactDetailResponse> > AddMemberContactAsync(vmMemberContactDetailRequest newMemberContactRequest) { var response = new SingleResponse <vmMemberContactDetailResponse>(); try { var newMemberContact = _mapper.Map <vmMemberContactDetailRequest, MemberContact>(newMemberContactRequest); // Create new payment payor await MemberContactRepository.AddMemberContactAsync(newMemberContact); // Fetch complete object from database newMemberContact = await MemberContactRepository.GetSingleMemberContactByIDAsync(newMemberContact.MemberContactID); // Convert from Domain Model to View Model var newMemberContactResponse = _mapper.Map <MemberContact, vmMemberContactDetailResponse>(newMemberContact); response.Model = newMemberContactResponse; response.Message = ResponseMessageDisplay.Success; } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <ISingleResponse <vmMemberContactDetailResponse> > UpdateMemberContactAsync(int memberContactId, vmMemberContactDetailRequest updateMemberContactRequest) { var response = new SingleResponse <vmMemberContactDetailResponse>(); try { var duplicateMemberContact = await MemberContactRepository.GetSingleMemberContactByNameAsync($"{updateMemberContactRequest.FirstName} {updateMemberContactRequest.LastName}"); if (duplicateMemberContact != null && duplicateMemberContact.MemberContactID != memberContactId) { response.Message = ResponseMessageDisplay.Duplicate; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(MemberMessageDisplay.MemberContactAlreadyExistedMessage, $"{updateMemberContactRequest.FirstName} {updateMemberContactRequest.LastName}")); } else { var memberContactFromDB = await MemberContactRepository.GetSingleMemberContactByIDAsync(memberContactId); if (memberContactFromDB == null) { response.Message = ResponseMessageDisplay.NotFound; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(MemberMessageDisplay.MemberContactNotFoundMessage)); } else { _mapper.Map <vmMemberContactDetailRequest, MemberContact>(updateMemberContactRequest, memberContactFromDB); await MemberContactRepository.UpdateMemberContactAsync(memberContactFromDB); // Fetch complete object from database memberContactFromDB = await MemberContactRepository.GetSingleMemberContactByIDAsync(memberContactFromDB.MemberContactID); // Convert from Domain Model to View Model var newMemberContactResponse = _mapper.Map <MemberContact, vmMemberContactDetailResponse>(memberContactFromDB); response.Model = newMemberContactResponse; response.Message = ResponseMessageDisplay.Success; } } } catch (Exception ex) { response.SetError(ex); } return(response); }