示例#1
0
        private void AttachUserToProject(AttachUserDTO attachUserDto)
        {
            using (var uow = CreateUnitOfWork())
            {
                Project project = uow.Projects.Get(attachUserDto.ProjectId);
                if (project == null)
                {
                    throw new ApplicationOperationException(string.Format("Project with id {0} not found", attachUserDto.ProjectId), HttpStatusCode.NotFound);
                }
                AppUser user = uow.Users.GetByEmail(attachUserDto.Email);
                if (user == null)
                {
                    throw new ApplicationOperationException(string.Format("User with email {0} not found", attachUserDto.Email), HttpStatusCode.NotFound);
                }

                AppRole role = uow.Roles.GetByName(attachUserDto.RoleName);
                if (role == null)
                {
                    throw new ApplicationOperationException(string.Format("Role with name {0} not found", attachUserDto.RoleName), HttpStatusCode.NotFound);
                }
                var userProjects = uow.UserProjects.Find(up => (up.ProjectId == project.Id && up.WorkerId == user.Id));
                if (userProjects.Count() > 0)
                {
                    throw new ApplicationOperationException(string.Format("User with email {0} already attach to project {1}", user.Email, project.Title), HttpStatusCode.Conflict);
                }
                UserProject userProject = new UserProject()
                {
                    Project = project, Worker = user, Role = role
                };
                uow.UserProjects.Add(userProject);
                uow.Complete();
            }
        }
示例#2
0
 public string ConfirmAttachmentUser(ConfirmAttachmentUserDTO confirmUserDto)
 {
     using (UoW)
     {
         Guid   id;
         string portalName = "";
         if (!Guid.TryParse(confirmUserDto.guid, out id))
         {
             throw new ApplicationOperationException(string.Format("Guid {0} is invalid", confirmUserDto.guid), HttpStatusCode.BadRequest);
         }
         var awaitAttach = UoW.AwaitingAttachmentUsers.Get(id);
         if (awaitAttach == null)
         {
             throw new ApplicationOperationException(string.Format("AwaitingAttachmentUser row with guid {0} not found", confirmUserDto.guid), HttpStatusCode.NotFound);
         }
         var attachUser = new AttachUserDTO()
         {
             Email = awaitAttach.Email, RoleName = awaitAttach.Role.Name, ProjectId = awaitAttach.ProjectId
         };
         var user = new AppUser()
         {
             Email = attachUser.Email, UserName = attachUser.Email
         };
         UoW.Users.Add(user, confirmUserDto.Password, attachUser.RoleName);
         //portalName = user.Portal.Title;
         UoW.Complete();
         AttachUserToProject(attachUser);
         UoW.AwaitingAttachmentUsers.Remove(awaitAttach);
         UoW.Complete();
         return(portalName);
     }
 }
示例#3
0
 public UserDTO UpdateAttachedUser(AttachUserDTO updateUserDto)
 {
     using (UoW)
     {
         var user        = UoW.Users.GetByEmail(updateUserDto.Email);
         var role        = UoW.Roles.GetByName(updateUserDto.RoleName);
         var userProject = UoW.UserProjects.Find(up => up.ProjectId == updateUserDto.ProjectId && up.WorkerId == user.Id).FirstOrDefault();
         userProject.Role = role;
         UoW.Complete();
         return(Mapper.Map <UserDTO>(userProject));
     }
 }
示例#4
0
        public UserDTO AttachUser(AttachUserDTO attachUserDto)
        {
            using (UoW)
            {
                AppUser user    = UoW.Users.GetByEmail(attachUserDto.Email);
                Project project = UoW.Projects.Get(attachUserDto.ProjectId);
                AppRole role    = UoW.Roles.GetByName(attachUserDto.RoleName);
                if (user == null) // значит в системе нет но к поекту надо прикрепить
                {
                    var guid           = Guid.NewGuid();
                    var attachmentUser = new AwaitingAttachmentUser()
                    {
                        Id      = guid,
                        Email   = attachUserDto.Email,
                        Project = project,
                        Role    = role
                    };
                    UoW.AwaitingAttachmentUsers.Add(attachmentUser);
                    UoW.Complete();
                    var uriBuilder = new UriBuilder(string.Format("http://*****:*****@")),
                        project.Title,
                        finalUrl.ToString()
                        );

                    _mailService.Send(
                        attachUserDto.Email,
                        "Sample Bug Tracker",
                        bodyMsg,
                        true
                        );
                    return(null);
                }

                AttachUserToProject(attachUserDto);
                var userDto = Mapper.Map <UserDTO>(user);
                userDto.RoleName = role.Name;
                return(userDto);
            }
        }
 public UserDTO UpdateAttachedUser([Required] AttachUserDTO updateUserDto)
 {
     return(_userService.UpdateAttachedUser(updateUserDto));
 }
 public UserDTO AttachUser([Required] AttachUserDTO attachUserDto)
 {
     return(_userService.AttachUser(attachUserDto));
 }