public int Save(ActivityDto activity)
        {
            using (var con = new SqlConnection(ConnectionString))
            {
                con.Open();

                var q =
                    con.Query<int>(
                        @"INSERT INTO Activity(ObjectID,ObjectType,ActivityDesc,ObjectTitle,OldState,NewState,TeamId,CreatedDate,CreatedByID) 
                        VALUES(@objectId,@objectType,@desc,@title,@oldState,@newState,@teamId,@createdDate,@userId);SELECT CAST(SCOPE_IDENTITY() as int)",
                        new
                        {
                            @objectId = activity.ObjectId,
                            @objectType = activity.ObjectType,
                            @title = activity.ObjectTitle,
                            @oldState = activity.OldState,
                            @newState = activity.NewState,
                            @desc = activity.Description,
                            @teamId = activity.TeamId,
                            @createdDate = DateTime.Now,
                            @userId = activity.Actor.Id


                        });

                return q.First();

            }
        }
        public ActivityDto SaveActivity(CreateIssue model, IssueDetailVM previousVersion, IssueDetailVM newVersion)
        {
            bool isStateChanged = false;
            var activity = new ActivityDto() { ObjectId = newVersion.Id, ObjectType = "Issue" };

            if (previousVersion == null)
            {
                activity.ObjectUrl = "issue/" + newVersion.Id;
                //activity.CreatedBy = 
                activity.Description = "Created";
                activity.ObjectTite = model.Title;
                isStateChanged = true;
            }
            else
            {
                if (previousVersion.Status.Id != newVersion.Status.Id)
                {
                    // status of issue updated
                    activity.Description = "Changed status";
                    activity.NewState = newVersion.Status.Name;
                    activity.OldState = previousVersion.Status.Name;
                    activity.ObjectTite = newVersion.Title;
                    isStateChanged = true;
                }
                else if (previousVersion.Category.Id != newVersion.Category.Id)
                {
                    activity.Description = "Changed category";
                    activity.NewState = newVersion.Category.Name;
                    activity.OldState = previousVersion.Category.Name;
                    activity.ObjectTite = newVersion.Title;
                    isStateChanged = true;
                }


            }

            activity.TeamId = userSessionHelper.TeamId;

            activity.Actor = new UserDto { Id = userSessionHelper.UserId };

            if (isStateChanged)
            {
                var newId = activityRepository.Save(activity);
                return activityRepository.GetActivityItem(newId);

            }
            return null;
        }
        public ActivityDto SaveActivity(int commentId, int issueId)
        {
            var issue = issueRepository.GetIssue(issueId);
            if (issue != null)
            {
                var activity = new ActivityDto() {ObjectId = commentId, ObjectType = "Comment"};
                activity.Description = "Commented";
                //activity.NewState = newVersion.Status.Name;
                // activity.OldState = previousVersion.Status.Name;
                activity.ObjectTite = issue.Title;
                activity.TeamId = userSessionHelper.TeamId;

                activity.Actor = new UserDto {Id = userSessionHelper.UserId};


                var newId = activityRepository.Save(activity);
                return activityRepository.GetActivityItem(newId);
                
            }
            return null;
        }
        public int Save(ActivityDto activity)
        {
            using (var db = new TeamEntitiesConn())
            {
                var a = new Activity
                {
                    OldState = activity.OldState,
                    NewState = activity.NewState,
                    ObjectID = activity.ObjectId,
                    ObjectType = activity.ObjectType,
                    ActivityDesc = activity.Description,
                    ObjectTitle = activity.ObjectTite,
                    CreatedByID = activity.Actor.Id,
                    TeamID = activity.TeamId,
                    CreatedDate = DateTime.Now
                };

                db.Activities.Add(a);
                db.SaveChanges();
                return a.ID;
            }
        }