public void AddUserToProjectsShare(Project project, ApplicationUser user, int userRole, ApplicationUser fromUser = null)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            if (userRole < UserRoleProjectsShareConstants.Invited && userRole > UserRoleProjectsShareConstants.Owner)
            {
                throw new ArgumentNullException(nameof(userRole));
            }

            using (var unitOfWork = _unitOfWorkFactory.GetUnitOfWork())
            {
                var projectsShare = unitOfWork.ProjectsShares.GetAll().FirstOrDefault(c => c.ProjectId.Equals(project.ProjectID)
                                            && c.UserId.Equals(user.Id));

                if (projectsShare != null)
                {
                    if (projectsShare.UserRole > UserRoleProjectsShareConstants.Invited)
                    {
                        throw new ArgumentException("User exists in projects share.");
                    }

                    projectsShare.UserRole = userRole;
                    unitOfWork.ProjectsShares.Update(projectsShare);
                }
                else
                {
                    var newprojectsShare = new ProjectsShare
                    {
                        ProjectId = project.ProjectID,
                        UserId = user.Id,
                        UserRole = userRole
                    };

                    if (fromUser != null)
                    {
                        newprojectsShare.FromUserId = fromUser.Id;
                    }

                    unitOfWork.ProjectsShares.Create(newprojectsShare);
                }

                unitOfWork.Save();
            }
        }
        public void AddEmailToProjectsShare(Project project, string email)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentException("Empty email.");
            }

            using (var unitOfWork = _unitOfWorkFactory.GetUnitOfWork())
            {
                var projectsShare = unitOfWork.ProjectsShares.GetAll().FirstOrDefault(c => c.ProjectID.Equals(project.ProjectID)
                                                                                           && c.SharedEmail.Equals(email));

                if (projectsShare != null)
                {
                    if (projectsShare.Delflag == DelflagConstants.UnactiveSet)
                    {
                        projectsShare.Delflag = DelflagConstants.ActiveSet;
                        unitOfWork.ProjectsShares.Update(projectsShare);
                    }
                    else if (projectsShare.Delflag == DelflagConstants.ActiveSet)
                    {
                        throw new ArgumentException("Email exists in projects shares.");
                    }
                }
                else
                {
                    var newprojectsShare = new ProjectsShare
                    {
                        ProjectID = project.ProjectID,
                        SharedEmail = email
                    };

                    unitOfWork.ProjectsShares.Create(newprojectsShare);
                }
                unitOfWork.Save();
            }
        }