Ejemplo n.º 1
0
        public ActionResult EditGroupTest(int groupInfoId, int?id)
        {
            var groupTest = new GroupTest();

            groupTest.TestPassRule = new TestPassRule();
            var modules        = new List <TestModule>();
            var modulePercents = new Dictionary <int, int>();

            if (id.HasValue)
            {
                GroupTestService.LoadWith(x => x.Test, x => x.TestPassRule);
                groupTest      = GroupTestService.GetByPK(id.Value);
                modulePercents = EntityUtils.GetModulePercents(groupTest.TestPassRule);
                modules        = TestModuleService.GetForTest(groupTest.TestId).ToList();
            }
            else
            {
                var groupId = GetGroupIdForInfo(groupInfoId);
                var group   = GroupService.GetByPK(groupId);
                groupTest.GroupInfoId = groupInfoId;
                groupTest.DateBegin   = group.DateBeg ?? DateTime.Now;
                groupTest.DateEnd     = group.DateEnd ?? DateTime.Now;
            }
            var model = new GroupTestEditVM {
                GroupTest      = groupTest,
                Modules        = modules,
                ModulePercents = modulePercents,
            };

            return(BaseView(new PagePart(new GroupTestEditView().Init(model, Url))));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Put(string id, [FromBody] GroupTest value)
        {
            try
            {
                //kiểm tra giống ID hay không
                if (id.Equals(value.Id, StringComparison.OrdinalIgnoreCase))
                {
                    value.Code = value.Code.ToLower().Trim();
                    //cập nhật UpdatedOn
                    value.UpdatedOn = DateTime.Now;
                    //không cho chỉnh người tạo và IsActive- đề phòng hack

                    /*value.CreatedBy = null;
                     * value.IsActive = true;*/
                    //cập nhật UpdatedOn
                    value.UpdatedOn = DateTime.Now;
                    value.UpdatedBy = UserClaim.UserId;
                    //gọi hàm update
                    var result = await _serviceGroupTest.UpdateAsync(id, value);

                    return(Ok(result));
                }
                return(BadRequest(StaticVar.MessageNotFound));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 3
0
 public async Task <IActionResult> AddOrEdit(string id, GroupTest data)
 {
     if (ModelState.IsValid)
     {
         //Insert
         if (String.IsNullOrEmpty(id))
         {
             try
             {
                 // check isset username ?
                 if (await ApiHelper <bool> .CheckIssetCode($"{StaticVar.ApiUrlGroups}/ExistsCode/{data.Code}"))
                 {
                     ModelState.AddModelError("", StaticVar.MessageCodeDuplicated);
                     return(Json(new
                     {
                         isValid = false,
                         html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data)
                     }));
                 }
                 else
                 {
                     try
                     {
                         GroupTest result = await ApiHelper <GroupTest> .RunPostAsync(StaticVar.ApiUrlGroups, data);
                     }
                     catch (Exception ex)
                     {
                         return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "Error", new ErrorViewModel {
                                 RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, Message = ex.Message
                             }) }));
                     }
                 }
             }
             catch (Exception ex)
             {
                 return(Json(new { isValid = false, mes = ex.Message }));
             }
         }
         //Update
         else
         {
             try
             {
                 await ApiHelper <GroupTest> .RunPutAsync($"{StaticVar.ApiUrlGroups}/{id}", data);
             }
             catch (Exception ex)
             {
                 return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "Error", new ErrorViewModel {
                         RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, Message = ex.Message
                     }) }));
             }
         }
         return(Json(new
         {
             isValid = true,
             html = MyViewHelper.RenderRazorViewToString(this, "_ViewAll", await ApiHelper <List <GroupTest> > .RunGetAsync($"{StaticVar.ApiUrlGroups}"))
         }));
     }
     return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data) }));
 }
Ejemplo n.º 4
0
        public GroupUserTests Create(GroupTest groupTest, List <int> userIds, UserTestService userTestService)
        {
            var userTests = userTestService.GetUserTests(groupTest).Where(x => userIds.Contains(x.UserId)).ToList();
            var best      =
                userTests.GroupBy(x => x.UserId).Select(x => x.OrderByDescending(y => y.Status).FirstOrDefault())
                .ToList();

            return(new GroupUserTests {
                GroupTest = groupTest, UserTests = best
            });
        }
Ejemplo n.º 5
0
 public void addGroupTest(GroupTest gt)
 {
     if (_admins.Where(a => a.AdminId.Equals(gt.AdminId)).Count() == 0 ||
         _groups.Where(g => g.AdminId.Equals(gt.AdminId) && g.name.Equals(gt.GroupName)).Count() == 0 ||
         _tests.Where(t => t.TestId == gt.TestId).Count() == 0 ||
         _groupsTests.Where(gtest => gtest.AdminId.Equals(gt.AdminId) && gtest.GroupName.Equals(gt.GroupName) && gtest.TestId == gt.TestId).Count() != 0)
     {
         return;
     }
     _groupsTests.Add(gt);
 }
Ejemplo n.º 6
0
 public void addGroupTest(GroupTest gt)
 {
     using (var db = new MedTrainDBContext())
     {
         if (db.Admins.Find(gt.AdminId) == null || db.Groups.Find(gt.AdminId, gt.GroupName) == null ||
             db.Tests.Find(gt.TestId) == null || db.GroupsTests.Find(gt.AdminId, gt.GroupName, gt.TestId) != null)
         {
             return;
         }
         db.GroupsTests.Add(gt);
         db.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 public async Task <ActionResult <GroupTest> > Post([FromBody] GroupTest data)
 {
     try
     {
         data.Code      = data.Code.ToLower().Trim();
         data.CreatedOn = DateTime.Now;
         data.CreatedBy = UserClaim.UserId;
         return(await _serviceGroupTest.InsertAsync(data));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 8
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var groupTests = new GroupTest
                {
                    Id   = request.id,
                    Name = request.Name
                };

                _context.GroupTest.Add(groupTests);
                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new Exception("Problem saving changes");
            }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine(new string('-', 50));

            //var N = BinaryGap.Solution(9);
            //Console.WriteLine("result: {0}", N);

            //var res = CyclicRotation.Solution(new int[] { 1, 2, 3, 4, 5 }, 2);
            //Console.WriteLine("result: {0}", string.Join(",", res));

            //CompareSearch.CompareSearches();

            //var b = new BinarySearch();
            //b.TestBinarySearch();

            //var s = new TwoSum();
            //var res = s.TestTwoSum(new int[] { 1, 6, 4, 5, 3, 3 }, 7);
            //Common.DisplayList(res);

            //var res1 = s.TestTwoSum1(new int[] { 1, 6, 4, 5, 3, 3 }, 7);
            //foreach (var item in res1)
            //    Common.DisplayItems(item);

            //var r = Common.GenerateArray(1, 100, 5);
            //Common.DisplayItems(r);

            //var r1 = Common.GenerateArray1(1, 100, 5);
            //Common.DisplayItems(r1);

            //var test = new NullableTypes();
            //test.nullable1();

            //var g = new GroupList();
            //g.GroupTest();

            var g = new GroupTest();

            g.ShowProducts();

            Console.WriteLine(new String('-', 50));
            //Console.ReadLine();
        }
Ejemplo n.º 10
0
        private void Button_AsignesTest_AddTest_Click(object sender, EventArgs e)
        {
            var testId = Convert.ToInt32(DGV_AsignesTest_AllTests.SelectedRows[0].Cells["Id"].Value);
            int groupId;

            try
            {
                groupId = repoGroup.FirstOrDefault(t => t.Name == comboBox_AsignesTest_Groups.SelectedItem.ToString()).Id;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Сhoose group first!", "Server Alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            GroupTest groupTest = new GroupTest()
            {
                GroupId = groupId, TestId = testId
            };

            var res = repoGroupTest.FirstOrDefault(t => t.GroupId == groupId && t.TestId == testId);

            if (res != null)
            {
                MessageBox.Show("You assigned this test once for this group", "Server Alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            repoGroupTest.Add(new GroupTest()
            {
                GroupId = groupId, TestId = testId
            });

            var bs = from g in repoGroup.GetAllData()
                     join gt in repoGroupTest.GetAllData() on g.Id equals gt.GroupId
                     join t in repoTest.GetAllData() on gt.TestId equals t.Id
                     where g.Id == groupId
                     select new { GroupName = g.Name, Author = t.Author, Title = t.Title, NumOfQuestions = t.NumOfQuestions, Time = t.Time };

            DGV_AsignesTest_TestsForGroup.DataSource = bs.ToList();
        }
Ejemplo n.º 11
0
 public IQueryable <UserTest> GetUserTests(GroupTest test)
 {
     return(this.GetAll(x => x.RunDate >= test.DateBegin &&
                        x.RunDate <= test.DateEnd.AddDays(1) && x.TestId == test.TestId));
 }
Ejemplo n.º 12
0
        private void Validate(GroupTest groupTest)
        {
            var rule = groupTest.TestPassRule;

            new TestValidators(ModelState).Validate(rule);
        }
Ejemplo n.º 13
0
 object GroupTestView(GroupTest groupTest)
 {
     return(div.Style("margin:10px 0px;")[strong["Тест:"], Url.TestLink(groupTest.Test)]);
 }
Ejemplo n.º 14
0
        public async Task <GroupTest> GetDetails(string id)
        {
            GroupTest GroupTest = await _serviceGroupTest.GetByIDAsync(id);

            return(GroupTest);
        }
Ejemplo n.º 15
0
        public void TestRolling()
        {
            Setup.EnsureBasicSetup();
            ItemMgr.InitMisc();

            // create group
            var group = GroupTest.CreateGroup(3);

            group.LootMethod = LootMethod.NeedBeforeGreed;

            var leaderMember = group.Leader;
            var leader       = (TestCharacter)leaderMember.Character;

            // create corpse
            var npc = Setup.NPCPool.CreateDummy();

            npc.EnsureInWorld();
            npc.FirstAttacker = leader;
            npc.Health        = 0;

            // create loot
            var loot = npc.Loot = new NPCLoot(npc, 0, new[] {
                new ItemStackTemplate(new ItemTemplate
                {
                    ItemId      = ItemId.Shortsword,
                    Id          = (uint)ItemId.Shortsword,
                    DefaultName = "Test Item1",
                    MaxAmount   = 3,
                    Quality     = ItemQuality.Artifact
                })
            });
            var lootItem = loot.Items[0];

            foreach (var member in group)
            {
                // let them all be next to the corpse
                ((TestCharacter)member.Character).EnsureXDistance(npc, 0.5f, true);
            }

            leader.Map.AddMessageAndWait(() => {
                var looters = LootMgr.FindLooters(npc, leader);
                Assert.AreEqual(group.CharacterCount, looters.Count);

                // initialize the Loot
                loot.Initialize(leader, looters, npc.MapId);
            });

            Assert.IsNotNull(lootItem.RollProgress);

            // everyone should now get the n/g box
            var i = 0;

            foreach (var member in group)
            {
                var chr = ((TestCharacter)member.Character);

                var rollStart = chr.FakeClient.DequeueSMSG(RealmServerOpCode.SMSG_LOOT_START_ROLL);
                Assert.IsNotNull(rollStart);

                Assert.AreEqual(npc.EntityId, rollStart["Looted"].Value);
                Assert.AreEqual(lootItem.Index, rollStart["ItemIndex"].Value);
                Assert.AreEqual(lootItem.Template.ItemId, rollStart["ItemTemplate"].Value);
                i++;
            }

            // let everyone roll
            var packet = new RealmPacketOut(RealmServerOpCode.CMSG_LOOT_ROLL);

            packet.Write(npc.EntityId);
            packet.Write(lootItem.Index);
            packet.Write((byte)LootRollType.Need);                      // need always before greed
            leader.FakeClient.ReceiveCMSG(packet, true);

            Assert.AreEqual(lootItem.RollProgress.HighestParticipant, leader);

            packet = new RealmPacketOut(RealmServerOpCode.CMSG_LOOT_ROLL);
            packet.Write(npc.EntityId);
            packet.Write(lootItem.Index);
            packet.Write((byte)LootRollType.Greed);
            ((TestCharacter)leaderMember.Next.Character).FakeClient.ReceiveCMSG(packet, true);

            Assert.AreEqual(lootItem.RollProgress.HighestParticipant, leader);
            Assert.AreEqual(1, lootItem.RollProgress.RemainingParticipants.Count);                              // one left

            packet = new RealmPacketOut(RealmServerOpCode.CMSG_LOOT_ROLL);
            packet.Write(npc.EntityId);
            packet.Write(lootItem.Index);
            packet.Write((byte)LootRollType.Greed);
            ((TestCharacter)leaderMember.Next.Next.Character).FakeClient.ReceiveCMSG(packet, true);

            // everyone rolled, item should have been given to the winner
            Assert.IsNull(lootItem.RollProgress);
            Assert.IsTrue(lootItem.Taken);
            Assert.IsTrue(leader.Inventory.Contains(lootItem.Template.Id, (int)lootItem.Amount, true));

            // since that was the only item: Loot should be unset and the corpse should now decay
            Assert.IsNull(npc.Loot);
            Assert.IsTrue(npc.IsDecaying);

            // TODO: Take money
            // TODO: Be not able to take items that are being rolled for
        }