public JsonResult AssociateMembers([FromBody] IncomingExistingProjectMembers accounts)
 {
     using (var context = new UsersContext(Context, Configuration))
     {
         context.AssociatedProjectExistingMembers(accounts);
     }
     return(Json(new IncomingExistingProjectMembers {
     }));
 }
Пример #2
0
        internal void AssociatedProjectExistingMembers(IncomingExistingProjectMembers accounts)
        {
            var projectRepository = Context.Projects.FirstOrDefault(x => x.Id == accounts.ProjectId).RepositoryId;

            accounts.Accounts.ForEach(y => {
                Context.AssociatedProjectMembers.Add(new AssociatedProjectMembers {
                    ProjectId     = accounts.ProjectId,
                    RepositoryId  = projectRepository,
                    UserAccountId = y.AccountId,
                });
                Context.SaveChanges();
                var commonRightsId  = default(int);
                var getCommonRights = Context.UserRights.FirstOrDefault(x => x.ManageIterations == y.IterationOptions &&
                                                                        x.ChatChannelsRule == y.ChatChannels &&
                                                                        x.ManageUserdays == y.ScheduleManagement &&
                                                                        x.UpdateUserRights == y.EditUserRights &&
                                                                        x.ViewOtherPeoplesWork == y.ViewWorkItems &&
                                                                        x.WorkItemRule == y.WorkItemOption);
                if (getCommonRights != null)
                {
                    commonRightsId = getCommonRights.Id;
                }
                else
                {
                    commonRightsId = Context.UserRights.Add(new UserRights {
                        ChatChannelsRule     = Convert.ToInt16(y.ChatChannels),
                        ManageIterations     = Convert.ToInt16(y.IterationOptions),
                        ViewOtherPeoplesWork = Convert.ToInt16(y.ViewWorkItems),
                        ManageUserdays       = Convert.ToInt16(y.ScheduleManagement),
                        UpdateUserRights     = Convert.ToInt16(y.EditUserRights),
                        WorkItemRule         = Convert.ToInt16(y.WorkItemOption)
                    }).Entity.Id;
                    Context.SaveChanges();
                }
                Context.AssociatedProjectMemberRights.Add(new AssociatedProjectMemberRights {
                    ProjectId     = accounts.ProjectId,
                    UserAccountId = y.AccountId,
                    RightsId      = commonRightsId
                });
                Context.SaveChanges();
            });
        }