Exemplo n.º 1
0
        public async Task <IActionResult> OnPostDeleteProjectAsync(int?id)
        {
            _log.LogWarning($"OnPost: MemberId {id}, DROP project {ProjectIdToDelete}");
            if (id == null)
            {
                return(NotFound());
            }

            Member = await _context.Members.Include(pm => pm.ProjectMembers).ThenInclude(p => p.Project).FirstOrDefaultAsync(m => m.MemberID == id);

            AllProjects = await _context.Projects.ToListAsync();

            ProjectDropDown = new SelectList(AllProjects, "ProjectID", "ProjectName");

            if (Member == null)
            {
                return(NotFound());
            }

            ProjectMember projectToDrop = _context.ProjectMembers.Where(pm => pm.ProjectID == ProjectIdToDelete && pm.MemberID == id).FirstOrDefault();

            if (projectToDrop != null)
            {
                _context.Remove(projectToDrop);
                _context.SaveChanges();
            }
            else
            {
                _log.LogWarning("Member not in project");
            }
            return(RedirectToPage(new { id = id }));
        }
        public int updateInfo(int managerId, ProjectMember member, bool joined)
        {
            int state;
            var req = WebRequest.Create(Server.ApiUrl + "/members/put/" + managerId + "/" + member.ProjectId);

            req.Method      = "POST";
            req.ContentType = "application/json";
            String contentData = "{" +
                                 "\"member\":" + "{" +
                                 "\"userId\":" + member.UserId + "," +
                                 "\"role\":\"" + member.Role + "\"," +
                                 "\"isJoined\":\"" + "0" + "\"}" +
                                 "}";

            using (var writer = new StreamWriter(req.GetRequestStream()))
            {
                writer.Write(contentData);
            }

            var resp = (HttpWebResponse)req.GetResponse();

            using (var reader = new StreamReader(resp.GetResponseStream()))
            {
                var     membertData    = reader.ReadToEnd();
                dynamic memberApiModel = JsonConvert.DeserializeObject <dynamic>(membertData);
                state = (int)memberApiModel;
            }
            Notify();
            return(state);
        }
Exemplo n.º 3
0
        public ActionResult Edit(ProjectMember projectMember)
        {
            if (ModelState.IsValid)
            {
                if (!DoIHaveAccessToProject(projectMember.ProjectId))
                {
                    return(RedirectToAction("NotAuthorized", "Error", new { area = "" }));
                }

                var selectedProjectMember = _projectMemberRepository.Get(projectMember.Id, "ProjectMemberRole");

                if (selectedProjectMember != null)
                {
                    selectedProjectMember.ProjectMemberRoleId = projectMember.ProjectMemberRoleId;
                    selectedProjectMember.Billing             = projectMember.Billing;
                    selectedProjectMember.Rate            = projectMember.Rate;
                    selectedProjectMember.UpdatedByUserId = WebUser.Id;

                    _projectMemberRepository.Update(selectedProjectMember);
                    _unitOfWork.Commit();
                    return(RedirectToAction("Details", "Projects", new { Id = projectMember.ProjectId }));
                }
            }

            return(View(projectMember));
        }
Exemplo n.º 4
0
        public async Task <(int newProjectMemberId, int newUserId)> AddProjectMember(int projectId, string email, string firstName, string lastName, int roleId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            (int newProjectMemberId, int newUserId) = (0, 0);

            var project = await _projectRepository.GetById(projectId, cancellationToken);

            if (project == null)
            {
                throw new ProjectNotFoundException(projectId);
            }

            var user = await _userRepository.GetByUserName(email, cancellationToken);

            if (user != null)
            {
                throw new DuplicateUserEmailException(email);
            }

            var newUser = new User {
                Email = email, UserName = email, FirstName = firstName, LastName = lastName
            };

            newUserId = await _userRepository.Create(newUser, cancellationToken);

            var newProjectMember = new ProjectMember {
                ProjectId = projectId, ProjectMemberRoleId = roleId, UserId = newUserId
            };

            newProjectMemberId = await _projectMemberRepository.Create(newProjectMember, cancellationToken);

            return(newProjectMemberId, newUserId);
        }
        public List <ProjectMember> getMemberByProjectId(int projectId, bool joined)
        {
            List <ProjectMember> memberList = new List <ProjectMember>();
            var req = WebRequest.Create(Server.ApiUrl + "/members/list/" + SecurityModel.getInstance().AuthenticatedUser.UserId + "/" + projectId);

            req.Method = "GET";
            var resp = (HttpWebResponse)req.GetResponse();

            using (var reader = new StreamReader(resp.GetResponseStream()))
            {
                var     membertData    = reader.ReadToEnd();
                dynamic memberApiModel = JsonConvert.DeserializeObject <dynamic>(membertData);
                int     state          = memberApiModel.state;
                if (state == 0)
                {
                    foreach (dynamic o in memberApiModel.member)
                    {
                        ProjectMember projectMember = new ProjectMember();
                        projectMember.UserId = o.userId;
                        projectMember.Role   = o.role;
                        int temp = BooltoString(joined);
                        if (int.Parse((String)o.isJoined) == temp)
                        {
                            memberList.Add(projectMember);
                        }
                    }
                }
            }
            return(memberList);
        }
        public void RemoveProjectMemberTest()
        {
            //Arrange
            ProjectMember projectMember1 = new ProjectMember {
                Id = 1, MemberId = 1, ProjectId = 1
            };
            ProjectMember projectMember2 = new ProjectMember {
                Id = 2, MemberId = 2, ProjectId = 1
            };

            _projectMemberRepositoryMock.SetupRepositoryMock(options =>
            {
                options.Insert(projectMember1);
                options.Insert(projectMember2);
            });

            var projectMemberService = new ProjectMemberService(_projectMemberRepositoryMock.Object);

            //Act
            projectMemberService.RemoveProjectMember(projectMember1);

            var actualProjectMember1 = projectMemberService.GetProjectMember(1, 1);
            var actualProjectMember2 = projectMemberService.GetProjectMember(1, 2);

            //Assert
            Assert.Null(actualProjectMember1);
            Assert.Equal(projectMember2.MemberId, actualProjectMember2.MemberId);
            Assert.Equal(projectMember2.ProjectId, actualProjectMember2.ProjectId);
            Assert.Equal(projectMember2.Id, actualProjectMember2.Id);
        }
        private void ListViewMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            UserControl usc = null;

            GridMain.Children.Clear();

            switch (((ListViewItem)((ListView)sender).SelectedItem).Name)
            {
            case "ItemDashboard":
                //new ProjectDashboard();
                usc = new ProjectMember();
                GridMain.Children.Add(usc);
                break;

            case "ItemProject":
                usc = new ProjectDetailsPM();
                GridMain.Children.Add(usc);
                break;

            case "ItemTask":
                usc = new TaskDashboard();
                GridMain.Children.Add(usc);
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Accept invitation
        /// </summary>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public async Task <ResultModel <AccountInfoModel> > AcceptInvitation(string activeCode)
        {
            ResultModel <AccountInfoModel> iResult = new ResultModel <AccountInfoModel>();

            ProjectMember inviteItem = await UnitOfWork
                                       .ProjectMemberRepository
                                       .GetAsync(c => c.IsPending && c.ActiveCode == activeCode);

            if (inviteItem == null)
            {
                iResult.Status = ActionStatus.NotFound;
            }
            else
            {
                inviteItem.IsPending = false;

                UnitOfWork.ProjectMemberRepository.Update(inviteItem);

                var result = await UnitOfWork.CommitAsync();

                if (result > 0)
                {
                    iResult.Data = await _accountBusiness.GetAccountInfo(inviteItem.MemberId);

                    iResult.Status = ActionStatus.Ok;
                }
            }
            return(iResult);
        }
Exemplo n.º 9
0
        public bool AddProjectMember(ProjectMember projectMember)
        {
            if (projectMember?.ProjectId == null)
            {
                throw new NoNullAllowedException(string.Format("ProjectId is empty").ToNotNullErrorMessage());
            }

            var project = GetById(projectMember.ProjectId.Value);

            if (project == null)
            {
                throw new NoNullAllowedException(string.Format("Project with id={0} had not been found", projectMember.ProjectId).ToNotNullErrorMessage());
            }

            //Check if the user exits in the same role in the project
            bool isUserInTheSameRole = project.ProjectMembers.Any(m => m.UserId == projectMember.UserId &&
                                                                  m.ProjectRoleId == projectMember.ProjectRoleId);

            if (isUserInTheSameRole)
            {
                throw new NoNullAllowedException(string.Format("User '{0}' is a member in the role '{1}' ", projectMember.User.UserName, projectMember.ProjectRole.Name).ToExistErrorMessage());
            }

            //Save<ProjectMember>
            project.ProjectMembers.Add(projectMember);
            UnitOfWork.SaveChanges();

            return(true);
        }
Exemplo n.º 10
0
        public async Task <(int newProjectMemberId, int newUserId)> AddProjectMember(int projectId, string email, string firstName, string lastName, Dictionary <string, string> externalAccountIds, int roleId, string webUrl, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var project = await _projectRepository.GetById(projectId, cancellationToken);

            if (project == null)
            {
                throw new ProjectNotFoundException(projectId);
            }

            var user = await _userService.GetUser(email, cancellationToken);

            if (user != null)
            {
                throw new DuplicateUserEmailException(email);
            }

            var newUser = await _userService.CreateUser(email, firstName, lastName, null, externalAccountIds, await _userService.GeneratePassword(), webUrl, cancellationToken);

            var newProjectMember = new ProjectMember {
                ProjectId = projectId, ProjectMemberRoleId = roleId, UserId = newUser.Id
            };
            var newProjectMemberId = await _projectMemberRepository.Create(newProjectMember, cancellationToken);

            return(newProjectMemberId, newUser.Id);
        }
Exemplo n.º 11
0
        public bool ThereIsAssignation(ProjectMember member)
        {
            var found =
                _projectMemberRepository.GetAllList(a => a.ProjectId == member.ProjectId && a.UserId == member.UserId);

            return(found.Count > 0);
        }
Exemplo n.º 12
0
        public ActionResult CreateProject(Project project)
        {
            //Check if there are any validation errors during model binding.
            //If validation is valid, Add project record to database
            //Else return view back to project

            if (ModelState.IsValid)
            {
                ProjectMember projectMember = new ProjectMember();

                //Add project record to database
                project.ProjectId = projectContext.Add(project);

                //set the property values for the projectmember to be prepared to insert into the database
                projectMember.ProjectId = project.ProjectId;

                //get the values for projectMember's studentID and set it to integer value
                projectMember.StudentId = HttpContext.Session.GetInt32("StudentID").Value;

                //projectmember role is = to  Leader
                projectMember.Role = "Leader";

                //projectContext method will add project as leader in projectmember
                projectContext.AddProjectAsLeader(projectMember);

                //Redirect user to Project/Index view
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(project));
            }
        }
Exemplo n.º 13
0
        // GET: Project
        public ActionResult Index()
        {
            if ((HttpContext.Session.GetString("Role") == null) ||
                (HttpContext.Session.GetString("Role") != "Student"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            ProjectMember projectmember = homeContext.getProjectID(HttpContext.Session.GetInt32("StudentID").Value);

            if (projectmember.Role != null || projectmember.ProjectId != 0)
            {
                HttpContext.Session.SetInt32("ProjectID", projectmember.ProjectId);
                HttpContext.Session.SetString("ProjectRole", projectmember.Role);
                List <Project> ProjectList = projectContext.GetAllProject(HttpContext.Session.GetInt32("StudentID"));
                System.Diagnostics.Debug.WriteLine(HttpContext.Session.GetString("ProjectRole"));


                //projectMemberList = projectContext method will getprojectmemberdetails by studentID in integer
                List <ProjectMember> projectMemberList = projectContext.GetProjectMemberDetails(HttpContext.Session.GetInt32("StudentID"));

                //Use ViewData to get ProjectList to view projectmemberList on _ViewProject.cshtml
                ViewData["ProjectList"] = projectMemberList;

                return(View(ProjectList));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            _log.LogWarning($"OnPost: ProjectID {id}, ADD members {MemberIdToAdd}");
            if (id == null)
            {
                return(NotFound());
            }
            Project = await _context.Projects.Include(pm => pm.ProjectMembers).ThenInclude(m => m.Member).FirstOrDefaultAsync(m => m.ProjectID == id);

            var memberList = _context.Members.Select(p => new { ID = p.MemberID, Display = string.Format($"{p.FirstName} {p.LastName}") }).Select(p => p);

            MemberDropDown = new SelectList(await memberList.Distinct().ToListAsync(), "ID", "Display");


            if (!_context.ProjectMembers.Any(pm => pm.MemberID == MemberIdToAdd && pm.ProjectID == id.Value))
            {
                ProjectMember memberToAdd = new ProjectMember {
                    ProjectID = id.Value, MemberID = MemberIdToAdd
                };
                _context.Add(memberToAdd);
                _context.SaveChanges();
            }
            else
            {
                _log.LogWarning("Project already has this member");
            }
            MemberIdToAdd = 0;
            return(RedirectToPage(new { id = id }));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> OnPostDeleteMemberAsync(int?id)
        {
            _log.LogWarning($"OnPost: ProjectID {id}, DROP member {MemberIdToDelete}");
            if (id == null)
            {
                return(NotFound());
            }

            Project = await _context.Projects.Include(pm => pm.ProjectMembers).ThenInclude(m => m.Member).FirstOrDefaultAsync(m => m.ProjectID == id);

            if (Project == null)
            {
                return(NotFound());
            }

            ProjectMember memberToDrop = _context.ProjectMembers.Where(pm => pm.MemberID == MemberIdToDelete && pm.ProjectID == id).FirstOrDefault();

            if (memberToDrop != null)
            {
                _context.Remove(memberToDrop);
                _context.SaveChanges();
            }
            else
            {
                _log.LogWarning("Member NOT assigned project");
            }
            return(Page());
        }
Exemplo n.º 16
0
        public JsonResult AddMember(ProjectMember projectMember, string member, int ProjectId)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = 400;

                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                return(Json(errorList, JsonRequestBehavior.AllowGet));
            }
            projectMember.ProjectId = ProjectId;

            string[] emails = member.Split(' ');
            foreach (var email in emails)
            {
                string e   = email.Split(',', '\t', ';')[0];
                var    usr = db.Users.FirstOrDefault(u => u.Email == e);
                if (usr != null)
                {
                    projectMember.UserId = usr.Id;
                }
                db.ProjectMembers.Add(projectMember);
                db.SaveChanges();
            }
            projectMember.Project = db.Projects.Find(projectMember.ProjectId);
            projectMember.User    = db.Users.Find(projectMember.UserId);
            return(Json(new
            {
                User = projectMember.User.Name + " " + projectMember.User.Surname,
                projectMember.User.Photo,
            }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Finish(int id)
        {
            ProjectMember m = ProjectMember.FindByID(id);

            m.Finish();
            return(RedirectToAction("Members", "Projects", new { id = m.ProjID }));
        }
Exemplo n.º 18
0
        public int deleteMember(int managerId, ProjectMember member)
        {
            int state = 0;
            var req   = WebRequest.Create(Server.ApiUrl + "/members/delete/" + managerId + "/" + member.ProjectId + "/" + member.UserId);

            req.Method      = "POST";
            req.ContentType = "application/json";
            String contentData = "{}";

            using (var writer = new StreamWriter(req.GetRequestStream()))
            {
                writer.Write(contentData);
            }

            var resp = (HttpWebResponse)req.GetResponse();

            using (var reader = new StreamReader(resp.GetResponseStream()))
            {
                var     membertData    = reader.ReadToEnd();
                dynamic memberApiModel = JsonConvert.DeserializeObject <dynamic>(membertData);
                state = (int)memberApiModel;
            }
            Notify();
            return(state);
        }
Exemplo n.º 19
0
        public JsonResult AssignMember(int projectId, int userId, int groupId)
        {
            var project = _projectService.GetProject(projectId);
            var user    = _userAccountService.GetUserById(userId);
            var group   = _userAccountService.GetGroup(groupId);

            var members    = project.Members;
            var userExists = members.Any(x => Equals(x.Usuario, user) && Equals(x.Grupo, @group));

            if (!userExists)
            {
                var member = new ProjectMember
                {
                    Project   = project,
                    Usuario   = user,
                    Grupo     = @group,
                    CreatedBy = User.Identity.Name,
                    CreatedOn = DateTime.Now
                };
                var confirmation = _projectService.SaveOrUpdateMember(member);
                return(Json(confirmation.WasSuccessful));
            }
            else
            {
                throw new Exception(" Usuario ya existe");
            }
        }
Exemplo n.º 20
0
        public int dealWithProjectInvitation(ProjectMember projectMember, bool isAccepted)
        {
            int state = -1;

            var req = WebRequest.Create(Server.ApiUrl + "/members/put/" + projectMember.UserId + "/" + projectMember.ProjectId);

            req.Method      = "POST";
            req.ContentType = "application/json";
            String contentData = "{\"member\":{\"userId\":\"" + projectMember.UserId + "\"," +
                                 "\"isJoined\":\"" + (isAccepted ? 1: 0).ToString() + "\"," +
                                 "\"role\":\"\"}}";

            using (var writer = new StreamWriter(req.GetRequestStream()))
            {
                writer.Write(contentData);
            }

            var resp = (HttpWebResponse)req.GetResponse();

            using (var reader = new StreamReader(resp.GetResponseStream()))
            {
                var memberData = reader.ReadToEnd();
                state = int.Parse((String)memberData);
            }
            Notify();

            return(state);
        }
Exemplo n.º 21
0
        public async Task <int> AddProjectMember(int projectId, int userId, int roleId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            var project = await _projectRepository.GetById(projectId, cancellationToken);

            if (project == null)
            {
                throw new ProjectNotFoundException(projectId);
            }

            var user = await _userRepository.GetById(userId, cancellationToken);

            if (user == null)
            {
                throw new UserNotFoundException(userId);
            }

            var projectMemberByProjectSpec = new ProjectMemberFilterSpecification(projectId, userId);
            var projectMember = await _projectMemberRepository.GetSingleBySpec(projectMemberByProjectSpec, cancellationToken);

            if (projectMember != null)
            {
                projectMember.ProjectMemberRoleId = roleId;
                await _projectMemberRepository.Update(projectMember, cancellationToken);

                return(projectMember.Id);
            }

            var newProjectMember = new ProjectMember {
                ProjectId = projectId, UserId = userId, ProjectMemberRoleId = roleId
            };

            return(await _projectMemberRepository.Create(newProjectMember, cancellationToken));
        }
Exemplo n.º 22
0
        public async Task <IActionResult> AddToProjectAsync([FromBody] AddToProjectViewModel model)
        {
            if (model.Email == null)
            {
                return(BadRequest());
            }

            var user = await _userManager.FindByEmailAsync(model.Email);

            // TODO: CHECK IF IN LIST AND SEND FAILURE

            if (user != null)
            {
                var result = new ProjectMember
                {
                    Employee           = user,
                    IsCreator          = false,
                    AcceptedInvitation = false,
                    ProjectId          = model.ProjectId,
                    ShowOnlyMine       = false
                };

                _context.Add(result);
                if (_context.SaveChanges() > 0)
                {
                    return(new JsonResult("success"));
                }
                else
                {
                    return(BadRequest());
                }
            }
            return(NotFound());
        }
 public ProjectMemberViewModel(ProjectMember entity)
 {
     Id        = entity.Id;
     CreatedAt = entity.CreatedAt;
     EntryDate = entity.EntryDate;
     Developer = new DeveloperViewModel(entity.Developer);
 }
Exemplo n.º 24
0
        /// <summary>
        /// 添加项目成员
        /// </summary>
        public ProjectMember Add(ProjectMember member)
        {
            var entity = _ctx.ProjectMembers.Add(member);

            _ctx.SaveChanges();
            return(entity);
        }
Exemplo n.º 25
0
        public async Task AddMembers(IEnumerable <MemberInput> input)
        {
            var     memberInputs = input as IList <MemberInput> ?? input.ToList();
            Project project      = null;

            if (memberInputs.ToList().Any())
            {
                project = _projectManager.GetProject(memberInputs.First().ProjectId);
            }
            foreach (var memberInput in memberInputs)
            {
                var projectMember = ProjectMember.CreateMember(memberInput.UserId, memberInput.ProjectId, memberInput.Leader);
                _membersManager.AddMember(projectMember);

                await _projectNotificationSubscriptionService.RegisterToGeneralNotifications(project, memberInput.UserId);

                if (memberInput.Leader)
                {
                    await _projectNotificationPublisherService.NotifyAddedAsLeader(project, memberInput.UserId);
                }
                else
                {
                    await _projectNotificationPublisherService.NotifyAddedMember(project, memberInput.UserId);
                }
            }
        }
        public async Task <ActionResult <ProjectMember> > PostProjectMember(ProjectMember projectMember)
        {
            _context.ProjectMember.Add(projectMember);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetProjectMember", new { id = projectMember.Id }, projectMember));
        }
Exemplo n.º 27
0
        public IHttpActionResult PutProjectMember(int id, ProjectMember projectMember)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != projectMember.Id)
            {
                return(BadRequest());
            }

            db.Entry(projectMember).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectMemberExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutProjectMember(int id, ProjectMember projectMember)
        {
            if (id != projectMember.Id)
            {
                return(BadRequest());
            }

            _context.Entry(projectMember).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProjectMemberExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 29
0
        public bool insert(ProjectMemberVM projectMemberVM)
        {
            var push       = new ProjectMember(projectMemberVM);
            var getRule    = applicationContext.Rules.Find(projectMemberVM.Rule_Id);
            var getProject = applicationContext.Projects.Find(projectMemberVM.Project_Id);

            if (getRule != null && getProject != null)
            {
                push.Rule    = getRule;
                push.Project = getProject;
                applicationContext.ProjectMembers.Add(push);
                var result = applicationContext.SaveChanges();
                if (result > 0)
                {
                    status = true;
                    return(status);
                }
                else
                {
                    return(status);
                }
            }
            else
            {
                return(status);
            }
        }
Exemplo n.º 30
0
        public async Task <IActionResult> Edit(int id, [Bind("ProjectId,PersonId")] ProjectMember projectMember)
        {
            if (id != projectMember.ProjectId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(projectMember);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectMemberExists(projectMember.ProjectId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PersonId"]  = new SelectList(_context.People, "PersonId", "FullName", projectMember.PersonId);
            ViewData["ProjectId"] = new SelectList(_context.Projects, "ProjectId", "Title", projectMember.ProjectId);
            return(View(projectMember));
        }
Exemplo n.º 31
0
 public MemberViewModel ToMemberViewModelFromProjectMember(ProjectMember projectMember)
 {
     return new MemberViewModel()
         {
             UserId = projectMember.UserId,
             UserName = projectMember.UserName,
             ImageName = projectMember.ImageUrl,
             Introduction = projectMember.Introduction,
             RoleName = projectMember.RoleName
         };
 }
Exemplo n.º 32
0
        private void FillDatabase(Dictionary<int, object[]> rowData, Project insertProject)
        {
            BarometerDataAccesLayer.DatabaseClassesDataContext context = DatabaseFactory.getInstance().getDataContext();
            foreach (KeyValuePair<int, object[]> cell in rowData)
            {
                bool userExists = false;

                if (cell.Key != 0 && cell.Value[0].ToString() != "")
                {
                    int studentNumber = int.Parse(cell.Value[0].ToString());
                    BarometerDataAccesLayer.User insertUser = null;
                    var existingUser =
                        from u in context.Users
                        where u.student_number == studentNumber
                        select u;

                    int test = 0;
                    if (!existingUser.Any())
                    {
                        //If doesnt exist, create empty one
                        insertUser = new BarometerDataAccesLayer.User();
                    }
                    else
                    {
                        //If exists, get user
                        userExists = true;
                        insertUser = existingUser.First();
                    }

                    insertUser.student_number = int.Parse(cell.Value[0].ToString());
                    insertUser.firstname = cell.Value[1].ToString();
                    insertUser.lastname = cell.Value[2].ToString();
                    insertUser.email = cell.Value[3].ToString();

                    if (cell.Value[4].ToString() != "")
                    {
                        string[] groups = cell.Value[4].ToString().Split(',');
                        foreach (string groupcode in groups)
                        {
                            bool groupExists = false;
                            var currentGroup =
                                from pg in context.ProjectGroups
                                where pg.group_code == groupcode
                                select pg;

                            ProjectGroup newGroup = null;
                            if (currentGroup.Count() == 0)
                            {
                                //Groep bestaat nog niet, aanmaken
                                newGroup = new ProjectGroup();
                                newGroup.group_code = groupcode;
                            }
                            else
                            {
                                groupExists = true;
                                newGroup = currentGroup.First();
                            }
                            if (insertProject != null)
                            {
                                newGroup.Project = insertProject;
                            }

                            ProjectMember member = new ProjectMember();
                            member.student_user_id = insertUser.id;
                            member.ProjectGroup = newGroup;
                            if (!groupExists)
                            {
                                context.ProjectGroups.InsertOnSubmit(newGroup);
                            }
                            context.ProjectMembers.InsertOnSubmit(member);
                        }
                    }
                    if (!userExists)
                    {
                        context.Users.InsertOnSubmit(insertUser);
                    }
                }
            }
            context.SubmitChanges();
        }