public MemberContentInteraction UpdateInteraction(int userId, MemberContentInteraction interactionToUpdate) { if (interactionToUpdate.Validate().Any()) { throw new System.ComponentModel.DataAnnotations.ValidationException(); } IUnitOfWork unitOfWork = new UnitOfWork <SALTEntities>(_dbContext); //TODO validation var existingInteraction = _ContentInteractionRepository.Get(m => m.MemberContentInteractionID == interactionToUpdate.MemberContentInteractionID && m.MemberID == userId).FirstOrDefault(); if (existingInteraction != null) { try { interactionToUpdate.ModifiedBy = GetUserPrincipalName(); interactionToUpdate.ModifiedDate = DateTime.Now; interactionToUpdate.CreatedBy = existingInteraction.CreatedBy; _ContentInteractionRepository.Update(interactionToUpdate); unitOfWork.Commit(); } catch (Exception ex) { _log.Error(ex.Message, ex); throw; } } return(interactionToUpdate); }
public MemberContentInteraction AddInteraction(MemberContentInteraction interaction) { if (interaction.Validate().Any()) { throw new System.ComponentModel.DataAnnotations.ValidationException(); } IUnitOfWork unitOfWork = new UnitOfWork <SALTEntities>(_dbContext); interaction.CreatedDate = DateTime.Now; interaction.InteractionDate = DateTime.Now; interaction.CreatedBy = GetUserPrincipalName(); try { _ContentInteractionRepository.Add(interaction); unitOfWork.Commit(); } catch (Exception ex) { _log.Error(ex.Message, ex); throw; } //TODO 2nd fetch to retreive model so that we can send back the ID that was created by stored proc??? //In insert loan the loan object automatically gets updated with the id, is this a timing thing?? return(interaction); }