public async void UserDetailsWorks(int id, string name)
        {
            var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>()
                          .UseInMemoryDatabase("create_user_test").Options;

            using (var db = new Data.D20CharacterDatabaseContext(options))
            {
                Lib.IRepo sut  = new Data.D20Repo(db);
                Lib.User  user = new Lib.User();
                if (await db.Gamer.FirstOrDefaultAsync(g => g.GamerId == 1) == null)
                {
                    user.UserID      = 0;
                    user.Username    = "******";
                    user.Characters  = new List <Lib.Character>();
                    user.MyCampaigns = new List <Lib.Campaign>();
                    db.Gamer.Add(user);
                    db.SaveChanges();
                }
                user.UserID      = id;
                user.Username    = name;
                user.Characters  = new List <Lib.Character>();
                user.MyCampaigns = new List <Lib.Campaign>();
                sut.CreateUser(user);

                Data.Gamer testUser = await db.Gamer.FirstOrDefaultAsync(u => u.UserName == name);

                bool actual = (testUser != null && testUser.UserName == name);
                Assert.True(actual);

                user   = sut.UserDetails(testUser.GamerId);
                actual = user.Username == name;

                Assert.True(actual);
            }
        }
        public PersSalesReport(DataRow row)
        {
            LpuRRList lpuRRList = LpuRRList.GetUniqueInstance();
            int idLpuRR;
            int.TryParse(row[0].ToString(), out idLpuRR);
            _lpuRR = lpuRRList.GetItem(idLpuRR) as LpuRR;

            UserList userList = UserList.GetUniqueInstance();
            int idUser;
            int.TryParse(row[1].ToString(), out idUser);
            _user = userList.GetItem(idUser) as User;

            RegionRRList regionRRList = RegionRRList.GetUniqueInstance();
            int idRegionRR;
            int.TryParse(row[2].ToString(), out idRegionRR);
            _regionRR = regionRRList.GetItem(idRegionRR) as RegionRR;

            int idSDiv;
            int.TryParse(row[3].ToString(), out idSDiv);
            _sdiv = (SDiv)idSDiv;

            int idRD;
            int.TryParse(row[4].ToString(), out idRD);
            _rd = userList.GetItem(idRD) as User;

            int.TryParse(row[5].ToString(), out _year);
            double.TryParse(row[6].ToString(), out _euro);
            double.TryParse(row[7].ToString(), out _rub);
        }
Пример #3
0
        public DataTable ToDataTable(User user, RegionRR regionRR, SDiv sdiv)
        {
            var list = List.Select(item => (item as UserLpuRR)).ToList();

            list = list.Where(item => item.User == user && item.LpuRR.RegionRR == regionRR && item.Sdiv == sdiv).OrderBy(item => item.LpuRR.Name).ToList();

            return CreateTable(list);
        }
Пример #4
0
 public UserLpuRR(User user, LpuRR lpuRR, SDiv sdiv)
 {
     _user = user;
     _lpuRR = lpuRR;
     _sdiv = sdiv;
     Name = string.Empty;
     _year1 = DateTime.Today.Year;
     _year2 = DateTime.Today.Year;
 }
        public PersonListController(DataGridView dgv, Organization organization)
            : base(dgv)
        {
            _organization = organization;
            _dgv = dgv;

            _seacher = new SearchInDgv(_dgv);
            _personList = PersonList.GetUniqueInstance();
            _user = UserLogged.Get();

            _filtredDGV = new FilteredDGV(dgv);
            _sortDGV = new SortDGV(dgv);
        }
        public OrganizationListController(DataGridView dgv)
            : base(dgv)
        {
            _dgv = dgv;
                        
            _userList = UserList.GetUniqueInstance();

            _lpuList = new LpuList();

            _user = _userList.GetItem(globalData.UserID) as User;

            _typeOrg = TypeOrg.ЛПУ;
        }
        public async void AddGMWorks()
        {
            var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>()
                          .UseInMemoryDatabase("add_gm_test").Options;

            using (var db = new Data.D20CharacterDatabaseContext(options))
            {
                Lib.IRepo sut  = new Data.D20Repo(db);
                Lib.User  user = new Lib.User();
                if (await db.Gamer.FirstOrDefaultAsync(g => g.GamerId == 1) == null)
                {
                    user.UserID      = 0;
                    user.Username    = "******";
                    user.Characters  = new List <Lib.Character>();
                    user.MyCampaigns = new List <Lib.Campaign>();
                    db.Gamer.Add(user);
                    db.SaveChanges();
                }
                user.UserID      = 0;
                user.Username    = "******";
                user.Characters  = new List <Lib.Character>();
                user.MyCampaigns = new List <Lib.Campaign>();
                sut.CreateUser(user);
                Lib.Campaign camp = new Lib.Campaign();
                if (await db.Campaign.FirstOrDefaultAsync(c => c.CampaignId == 1) == null)
                {
                    camp.CampID     = 0;
                    camp.Name       = "No Campaign";
                    camp.Characters = new List <Lib.Character>();
                    camp.GMs        = new List <Lib.User>();
                    db.Campaign.Add(camp);
                    db.SaveChanges();
                }
                camp.CampID     = 0;
                camp.Name       = "Test Campaign";
                camp.Characters = new List <Lib.Character>();
                camp.GMs        = new List <Lib.User>();
                sut.CreateCampaign(camp);
                user = await db.Gamer.FirstOrDefaultAsync(u => u.UserName == "Test User");

                camp = await db.Campaign.FirstOrDefaultAsync(c => c.CampaignName == "Test Campaign");

                sut.AddGM(camp.CampID, user.UserID);

                var result = await db.Gmjunction.FirstOrDefaultAsync(g => g.CampaignId == camp.CampID);

                bool actual = result.Gmid == user.UserID;

                Assert.True(actual);
            }
        }
        public DataGridView ToDataGridView(User user, RegionRR regionRR, SDiv sdiv)
        {
            DataTable dt = _userLpuRRList.ToDataTable(user, regionRR, sdiv);

            _dgv.DataSource = dt;

            _dgv.Columns[0].Visible = false;
            _dgv.Columns[1].Width = 50;
            _dgv.Columns[2].Width = 88;
            _dgv.Columns[3].Width = 200;
            _dgv.Columns[4].Width = 65;
            _dgv.Columns[5].Width = 65;

            SetStyle();

            return _dgv;
        }
        public async void UserListWorks()
        {
            var options = new DbContextOptionsBuilder <Data.D20CharacterDatabaseContext>()
                          .UseInMemoryDatabase("user_list_test").Options;

            using (var db = new Data.D20CharacterDatabaseContext(options))
            {
                Lib.IRepo sut  = new Data.D20Repo(db);
                Lib.User  user = new Lib.User();
                if (await db.Gamer.FirstOrDefaultAsync(g => g.GamerId == 1) == null)
                {
                    user.UserID      = 0;
                    user.Username    = "******";
                    user.Characters  = new List <Lib.Character>();
                    user.MyCampaigns = new List <Lib.Campaign>();
                    db.Gamer.Add(user);
                    db.SaveChanges();
                }
                user.UserID      = 0;
                user.Username    = "******";
                user.Characters  = new List <Lib.Character>();
                user.MyCampaigns = new List <Lib.Campaign>();
                sut.CreateUser(user);
                Lib.User user2 = new Lib.User();
                user2.UserID      = 0;
                user2.Username    = "******";
                user2.Characters  = new List <Lib.Character>();
                user2.MyCampaigns = new List <Lib.Campaign>();
                sut.CreateUser(user2);

                Data.Gamer testUser = await db.Gamer.FirstOrDefaultAsync(u => u.UserName == user.Username);

                Data.Gamer testUser2 = await db.Gamer.FirstOrDefaultAsync(u => u.UserName == user2.Username);

                bool actual = (testUser != null && testUser.UserName == user.Username && testUser2 != null && testUser2.UserName == user2.Username);
                Assert.True(actual);

                IList <Lib.User> list = (IList <Lib.User>)sut.UserList();
                actual = (list.Count == 3 && list[1].Username == user.Username && list[2].Username == user2.Username);

                Assert.True(actual);
            }
        }
Пример #10
0
        public UserLpuRR(DataRow row)
            : base(row)
        {
            int idUser;
            int.TryParse(row[1].ToString(), out idUser);
            UserList userList = UserList.GetUniqueInstance();
            _user = userList.GetItem(idUser) as User;

            int idLpuRR;
            int.TryParse(row[2].ToString(), out idLpuRR);
            LpuRRList lpuRRList = LpuRRList.GetUniqueInstance();
            _lpuRR = lpuRRList.GetItem(idLpuRR) as LpuRR;

            int idSdiv;
            int.TryParse(row[3].ToString(), out idSdiv);
            _sdiv = (SDiv)idSdiv;

            int.TryParse(row[4].ToString(), out _year1);
            int.TryParse(row[5].ToString(), out _year2);
        }
Пример #11
0
        public DataTable ToDataTableWithLpuSF(User user)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("№ ЛПУ-RR", typeof(int));
            dt.Columns.Add("Сокр. название ЛПУ-RR");
            dt.Columns.Add("Полное название ЛПУ-RR");
            dt.Columns.Add("Регион RR");
            dt.Columns.Add("Статус");
            dt.Columns.Add("Использование");
            dt.Columns.Add("Сокр. название ЛПУ-SF");
            dt.Columns.Add("Регион России");
            dt.Columns.Add("Город");
            dt.Columns.Add("№ ЛПУ-SF");
            dt.Columns.Add("color");

            LpuList lpuList = new LpuList();

            List<LpuRR> listNew = new List<LpuRR>();
            listNew = List.Select(item => item as LpuRR).ToList();

            if (user.RoleSF == RolesSF.Пользователь)
            {
                UserRightList userRightList = UserRightList.GetUniqueInstance();

                listNew = listNew.Where(item => userRightList.IsInList(user, item.RegionRR)).ToList();
            }

            foreach (LpuRR lpuRR in listNew)
            {
                if (lpuRR.ID == 0)
                    continue;

                LPU lpu = lpuList.GetItem(lpuRR);

                string lpuName = string.Empty;
                string realRegionName = string.Empty;
                string cityName = string.Empty;
                string lpuID = string.Empty;

                if (lpu != null)
                {
                    lpuName = lpu.ShortName;
                    realRegionName = (lpu.RealRegion != null) ? lpu.RealRegion.Name : string.Empty;
                    cityName = lpu.City;
                    lpuID = lpu.ID.ToString();
                }

                bool colorWhite = true;

                if (user.RoleSF == RolesSF.Пользователь)
                {
                    colorWhite = IsUserLpu(lpuRR, user);
                }

                dt.Rows.Add(new object[] { lpuRR.ID, lpuRR.Name, lpuRR.FullName, lpuRR.RegionRR.Name, lpuRR.StatusLPU.ToString(),
                    (IsLpuUsed(lpuRR) ? "Используется" : "Не используется"),
                    lpuName, realRegionName, cityName, lpuID, colorWhite });
            }

            return dt;
        }
Пример #12
0
        public DataTable ToDataTable(User user)
        {
            List<LpuRR> list = List.Select(item => item as LpuRR).ToList();
            list = list.Where(item => !item.IsInList && item.StatusLPU == StatusLPU.Активен).OrderBy(item => item.Name).OrderBy(item => item.RegionRR.Name).ToList();

            if (user.RoleSF == RolesSF.Пользователь)
            {
                UserRightList userRightList = UserRightList.GetUniqueInstance();

                list = list.Where(item => userRightList.IsInList(user, item.RegionRR)).ToList();
            }

            DataTable dt = new DataTable();
            dt.Columns.Add("№ ЛПУ-RR");
            dt.Columns.Add("Сокр. название ЛПУ-RR");
            dt.Columns.Add("Полное название ЛПУ-RR");
            dt.Columns.Add("Регион RR");

            foreach (LpuRR item in list)
                dt.Rows.Add(new object[] { item.ID, item.Name, item.FullName, item.RegionRR.Name });

            dt.Rows.Add(new object[] { 0, "Прочие ЛПУ", "Прочие ЛПУ", "Российская федерация" });

            return dt;
        }
Пример #13
0
        public string Save(User userLogged)
        {
            if (ID == 0)
            {
                int idUserLpu;
                int.TryParse(_provider.Insert("UserLPU", ID, _user.ID, _lpuRR.ID, _sdiv, userLogged.ID), out idUserLpu);
                ID = idUserLpu;

                UserLpuRRList userLpuRRList = UserLpuRRList.GetUniqueInstance();
                userLpuRRList.Add(this);

                return "1";
            }
            else
            {
                return _provider.Update("UserLPU", ID, _user.ID, YearBegin, YearEnd);
            }
        }
Пример #14
0
 public bool IsInList(LpuRR lpuRR, User user)
 {
     var list = List.Select(item => item as UserLpuRR).ToList();
     return list.Exists(item => item.LpuRR == lpuRR && item.User == user && item.YearEnd >= DateTime.Today.Year);
 }
Пример #15
0
        public DataTable ToDataTableWithSF(User user)
        {
            var list = List.Select(item => item as UserLpuRR).ToList();

            if (user.RoleSF == RolesSF.Пользователь)
            {
                UserRightList userRightList = UserRightList.GetUniqueInstance();

                list = list.Where(item => userRightList.IsInList(user, item.LpuRR.RegionRR)).ToList();

                RoleList roleList = RoleList.GetUniqueInstance();
                Role role = roleList.GetItem(ROLE_RP_ID) as Role;

                if (user.Role == role)
                    list = list.Where(item => item.User == user).ToList();
            }

            //list = list.Where(item => item.YearEnd == DateTime.Today.Year).ToList();

            DataTable dt = new DataTable();
            dt.Columns.Add("№ ЛПУ-RR", typeof(int));
            dt.Columns.Add("ФИО РП");
            dt.Columns.Add("Дивизион");
            dt.Columns.Add("Начало отчётности");
            dt.Columns.Add("Окончание отчётности");
            dt.Columns.Add("Сокр. название ЛПУ-RR");
            dt.Columns.Add("Полное название ЛПУ-RR");
            dt.Columns.Add("Регион RR");
            dt.Columns.Add("Статус");
            dt.Columns.Add("Сокр. название ЛПУ-SF");
            dt.Columns.Add("Регион России");
            dt.Columns.Add("Город");
            dt.Columns.Add("№ ЛПУ-SF");

            LpuList lpuList = new LpuList();

            foreach (UserLpuRR item in list)
            {
                if ((item.LpuRR == null) || (item.User == null))
                    continue;

                string lpuSFID = string.Empty;
                string lpuSFName = string.Empty;
                string lpuSFRealRegion = string.Empty;
                string lpuSFCity = string.Empty;

                LPU lpu = lpuList.GetItem(item.LpuRR);

                if (lpu != null)
                {
                    lpuSFID = lpu.ID.ToString();
                    lpuSFName = lpu.ShortName;
                    lpuSFRealRegion = lpu.RealRegion.Name;
                    lpuSFCity = lpu.City;
                }

                dt.Rows.Add(new object[] { item.LpuRR.ID, item.User.Name, item.Sdiv.ToString(), item.YearBegin, item.YearEnd, item.LpuRR.Name, item.LpuRR.FullName,
                    item.LpuRR.RegionRR.Name, item.LpuRR.StatusLPU.ToString(), lpuSFName, lpuSFRealRegion, lpuSFCity, lpuSFID });
            }

            return dt;
        }
Пример #16
0
 public List<RegionRR> ToList(User user)
 {
     return _list.Where(item => (item as UserRight).User == user).Select(item => (item as UserRight).RegionRR).ToList();
 }
Пример #17
0
 public bool IsInList(User user, RegionRR regionRR)
 {
     return _list.Exists(item => (item as UserRight).User == user && (item as UserRight).RegionRR == regionRR);
 }
Пример #18
0
        private bool IsUserLpu(LpuRR lpuRR, User user)
        {
            UserLpuRRList userLpuRRList = UserLpuRRList.GetUniqueInstance();

            return userLpuRRList.IsInList(lpuRR, user);
        }