示例#1
0
 public void UnattachUser(UnattachUserDTO unattachUserDto)
 {
     using (UoW)
     {
         Project project = UoW.Projects.Get(unattachUserDto.ProjectId);
         if (project == null)
         {
             throw new ApplicationOperationException(string.Format("Project with id {0} not found", unattachUserDto.ProjectId), HttpStatusCode.NotFound);
         }
         AppUser user = UoW.Users.GetByEmail(unattachUserDto.Email);
         if (user == null)
         {
             throw new ApplicationOperationException(string.Format("User with email {0} not found", unattachUserDto.Email), HttpStatusCode.NotFound);
         }
         var userProject = UoW.UserProjects.Find(up => up.ProjectId == project.Id && up.WorkerId == user.Id).FirstOrDefault();
         if (userProject == null)
         {
             throw new ApplicationOperationException(string.Format("User with email {0} not attached to project {1}", unattachUserDto.Email, project.Title), HttpStatusCode.NotFound);
         }
         UoW.UserProjects.Remove(userProject);
         var errors = project.Errors.Where(e => e.AuthorId == user.Id);
         foreach (var error in errors)
         {
             error.Assignee   = null;
             error.AssigneeId = null;
         }
         UoW.Complete();
     }
 }
 public void UnattachUser([Required] UnattachUserDTO unattachUserDto)
 {
     _userService.UnattachUser(unattachUserDto);
 }