public async Task <IActionResult> Acknowledge([FromBody] AcknowledgeUserCommunication acknowledgeUserCommunication) { if (_userContext.UserId.HasValue) { return(await ResultHelper(async() => { return await _userCommunicationService.Acknowledge(_userContext.UserId.Value, acknowledgeUserCommunication); })); } return(Error <List <UserCommunicationData> >("Invalid User. User must be logged in")); }
public async Task <CrudResult <List <UserCommunicationData> > > Acknowledge(Guid identUserId, AcknowledgeUserCommunication acknowledgeUserCommunication) { try { var user = await Context.Users.SingleOrDefaultAsync(u => u.IdentUserId == UserContext.UserId); var result = CrudResult <List <UserCommunicationData> > .Create(); var newAcknowledgement = new UserCommunicationAcknowledgementEntity() { Acknowledged = true, AcknowledgedDate = DateTime.Now, UserId = user.UserId, UserCommunicationId = acknowledgeUserCommunication.UserCommunicationId }; Context.UserCommunicationAcknowledgements.Add(newAcknowledgement); await Context.SaveChangesAsync(user.Username); var getUserCommunicationsResult = await GetUserCommunicationsForDisplay(identUserId); if (result.Successful) { result.Data = getUserCommunicationsResult.Data; } else { result.Data = new List <UserCommunicationData>(); result.AddWarning("Unable to retive updated User Communications"); result.AddExceptions(getUserCommunicationsResult.Exceptions.ToArray()); } return(result); } catch (Exception ex) { return(CrudResult <List <UserCommunicationData> > .Create(ex)); } }