private void UpdateMemberPropertiesForMember(MemberEditDto dto, MemberProfile member) { var tempMember = _mapper.Map <MemberProfile>(dto); member.Email = tempMember.Email; member.Address = tempMember.Address; member.City = tempMember.City; member.PostalCode = tempMember.PostalCode; member.MainPhone = tempMember.MainPhone; member.AlternatePhone1 = tempMember.AlternatePhone1; member.AlternatePhone2 = tempMember.AlternatePhone2; member.Birthdate = tempMember.Birthdate; member.EmergencyFullName = tempMember.EmergencyFullName; member.EmergencyPhone1 = tempMember.EmergencyPhone1; member.EmergencyPhone2 = tempMember.EmergencyPhone2; member.EmergencyRelationship = tempMember.EmergencyRelationship; member.FoodSafe = tempMember.FoodSafe; member.FoodSafeExpiry = tempMember.FoodSafeExpiry; member.FirstAidCprLevel = tempMember.FirstAidCprLevel; member.FirstAidCpr = tempMember.FirstAidCpr; member.FirstAidCprExpiry = tempMember.FirstAidCprExpiry; member.OtherCertificates = tempMember.OtherCertificates; member.VolunteerConfidentiality = tempMember.VolunteerConfidentiality; member.VolunteerEthics = tempMember.VolunteerEthics; member.CriminalRecordCheck = tempMember.CriminalRecordCheck; member.DrivingAbstract = tempMember.DrivingAbstract; member.ConfirmationOfProfessionalDesignation = tempMember.ConfirmationOfProfessionalDesignation; member.ChildWelfareCheck = tempMember.ChildWelfareCheck; member.Positions = tempMember.Positions; }
public async Task UpdateMember(MemberEditDto model) { var services = new Microsoft.Extensions.DependencyInjection.ServiceCollection(); var mapper = services.GetService <IMapper>(); using (var db = base.NewDb()) { var member = await db.Member.FindAsync(model.UserId); mapper.Map(model, member); if (member.MemberDetail == null) { var memberDetail = new MemberDetail() { UserId = model.UserId, Introduction = model.Introduction, LikeCondition = model.LikeCondition }; member.MemberDetail = memberDetail; } else { member.MemberDetail.Introduction = model.Introduction; member.MemberDetail.LikeCondition = model.LikeCondition; } db.Entry(member).State = EntityState.Modified; await db.SaveChangesAsync(); } }
public async Task <ApiResult <MemberEditDto> > UpdateMemberForMember(MemberEditDto dto) { try { var member = await _context.Members.FirstOrDefaultAsync(m => m.Id == dto.Id); // TODO: update identity account username before updating the rest of member information UpdateMemberPropertiesForMember(dto, member); // detach all positions to prevent duplicate entity tracking error when saving foreach (var position in dto.Positions) { _context.Entry(position).State = EntityState.Detached; } await _context.SaveChangesAsync(); var result = await GetMember <MemberEditDto>(member.Id); return(result); } catch (Exception ex) { _logger.LogError("An issue occured when trying to update a member: \n" + ex.Message + "\n\nStack Trace: \n" + ex.StackTrace); return(new ApiResult <MemberEditDto> { Successful = false, Error = "An issue occured when trying to update a member." }); } }
public virtual async Task UpdateMemberAsync(MemberEditDto input) { //TODO:更新前的逻辑判断,是否允许更新 var entity = await _memberRepository.GetAsync(input.Id.Value); input.MapTo(entity); await _memberRepository.UpdateAsync(entity); }
public virtual async Task <MemberEditDto> CreateMemberAsync(MemberEditDto input) { //TODO:新增前的逻辑判断,是否允许新增 var entity = input.MapTo <Member>(); entity = await _memberRepository.InsertAsync(entity); return(entity.MapTo <MemberEditDto>()); }
protected virtual async Task Update(MemberEditDto input) { //TODO:更新前的逻辑判断,是否允许更新 var entity = await _entityRepository.GetAsync(input.Id.Value); //input.MapTo(entity); ObjectMapper.Map(input, entity); await _entityRepository.UpdateAsync(entity); }
public async Task <IActionResult> UpdateMember(int userId, MemberEditDto model) { if (userId != int.Parse(User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } await _service.UpdateMember(model); return(Ok()); }
protected virtual async Task <MemberEditDto> Create(MemberEditDto input) { //TODO:新增前的逻辑判断,是否允许新增 // var entity = ObjectMapper.Map <Member>(input); var entity = input.MapTo <Member>(); entity = await _entityRepository.InsertAsync(entity); return(entity.MapTo <MemberEditDto>()); }
/// <summary> /// 通过Id获取个人会员信息表信息进行编辑或修改 /// </summary> public async Task <GetMemberForEditOutput> GetMemberForEditAsync(NullableIdDto <int> input) { var output = new GetMemberForEditOutput(); MemberEditDto memberEditDto; if (input.Id.HasValue) { var entity = await _memberRepository.GetAsync(input.Id.Value); memberEditDto = entity.MapTo <MemberEditDto>(); } else { memberEditDto = new MemberEditDto(); } output.Member = memberEditDto; return(output); }
public static MemberEditDto GenerateNonAdminMemberDto(int id) { var dto = new MemberEditDto { Id = id, Email = $"*****@*****.**", Address = "testAddress", City = "testcity", PostalCode = "T1R1L9", MainPhone = "5555555555", AlternatePhone1 = "5555555555", AlternatePhone2 = "5555555555", EmergencyFullName = "testemergency", EmergencyPhone1 = "5555555555", EmergencyPhone2 = "5555555555", EmergencyRelationship = "testrelationship", }; return(dto); }
public async Task <GetMemberForEditOutput> GetForEdit(NullableIdDto <Guid> input) { var output = new GetMemberForEditOutput(); MemberEditDto editDto; if (input.Id.HasValue) { var entity = await _entityRepository.GetAsync(input.Id.Value); editDto = entity.MapTo <MemberEditDto>(); //memberEditDto = ObjectMapper.Map<List<memberEditDto>>(entity); } else { editDto = new MemberEditDto(); } output.Member = editDto; return(output); }
public async Task <IActionResult> UpdateMemberForMember([FromBody] MemberEditDto dto) { return(new ObjectResult(await _teamService.UpdateMemberForMember(dto))); }