public void UpdateUserGoal(DhaUserGoalDto userGoalDto) { var dhaUser = _unitOfWork.DhaUserRepository.Find(userGoalDto.DhaUserId); var userGoal = dhaUser.Goals.FirstOrDefault(x => x.Id == userGoalDto.Id); if (userGoal != null) { userGoal.StartValue = userGoalDto.StartValue; userGoal.TargetValue = userGoalDto.TargetValue; userGoal.CurrentValue = userGoalDto.CurrentValue; userGoal.EndValue = userGoalDto.EndValue; userGoal.StartDate = userGoalDto.StartDate; userGoal.DueDate = userGoalDto.DueDate; userGoal.IsActive = userGoalDto.IsActive; } _unitOfWork.Commit(); }
public void AddUserGoals(DhaUserGoalDto userGoalDto) { var dhaUser = _unitOfWork.DhaUserRepository.Find(userGoalDto.DhaUserId); foreach (var userGoal in dhaUser.Goals.Where(x => x.Type == userGoalDto.Type)) { dhaUser.Goals.Remove(userGoal); } dhaUser.Goals.Add(new DhaUserGoal { Id = userGoalDto.Id, StartDate = userGoalDto.StartDate, DueDate = userGoalDto.DueDate, Type = userGoalDto.Type }); _unitOfWork.Commit(); }