public async Task <IActionResult> GetActivity(int userId, int partyId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var repoActivity = await _repoActivity.GetActivityMember(userId, partyId); var dtoActivity = _mapper.Map <DtoActivityAudit>(repoActivity); return(Ok(dtoActivity)); }
public async Task <IActionResult> sendActivityOrder(int userId, int partyId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var member = await _repoMember.Get(userId); if (member == null) { return(NotFound()); } var party = await _repoParty.Get(partyId); if (party == null) { return(NotFound()); } var activity = await _repoActivity.GetActivityMember(userId, partyId); if (activity != null) { return(BadRequest("您已經有報名了,不可以重復報名")); } if (member.IsBlackUser > 0) { return(BadRequest("由於您有不佳的記錄,無法參加本會的活動")); } if (member.Marry > party.Marry) { return(BadRequest("您的婚姻狀況資格不符,請參加符合您條件的場次")); } var myAge = member.BirthYear.CalculateYears(); if (member.Sex == 1) { if (myAge > party.ManAge2 || myAge < party.ManAge1) { return(BadRequest("您的年齡資格不符,請參加符合您條件的場次")); } if (member.Education < party.ManEducaton) { return(BadRequest("您的學歷資格不符,請參加符合您條件的場次")); } } else { if (myAge > party.WomanAge2 || myAge < party.WomanAge1) { return(BadRequest("您的年齡資格不符,請參加符合您年齡的場次")); } if (member.Education < party.WomanEducaton) { return(BadRequest("您的學歷資格不符,請參加符合您條件的場次")); } } var today = System.DateTime.Today; int amt; if (today <= party.EarlyDate) { if (member.Sex == 1) { amt = (int)party.EarlyManAmt; } else { amt = (int)party.EarlyWomanAmt; } } else { if (member.Sex == 1) { amt = party.ManAmt; } else { amt = party.WomanAmt; } } var result = new Activity { UserId = userId, PartyId = partyId, ApplyDate = today, ActAmt = amt, CheckOver = 0, MyNo = 0 }; _repoActivity.Add <Activity>(result); if (_repoActivity.SaveAll() > 0) { return(Ok()); } return(BadRequest("寫入資料庫失敗,請洽詢服務人員")); }