예제 #1
0
        public ActionResult Create([Bind(Include = "ChoicerID,FCategoryID,FCUserID,CQuestion,Opt1,Opt2,Opt3,Opt4,Opt5,CAnswer,IsShareOnline,IsFavourite,IsSkip,Appearance,WAppearance,Score,AdditionalInfo")] Choicer choicer, bool checkResp = false)
        {
            if (ModelState.IsValid)
            {
                if (Session["UserID"] != null)
                {
                    if (checkResp == true)
                    {
                        choicer.IsShareOnline = true;
                    }
                    else
                    {
                        choicer.IsShareOnline = false;
                    }
                    if (Session["UserID"] != null)
                    {
                        string id = Session["UserID"].ToString();
                        choicer.FCUserID = Convert.ToInt32(id);
                    }

                    choicer.FCUserID = userid;

                    db.Choicers.Add(choicer);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.FCategoryID = new SelectList(db.Categories, "CategoryID", "Name", choicer.FCategoryID);
            // ViewBag.FCUserID = new SelectList(db.Users, "UserID", "Forename", choicer.FCUserID);
            //ViewBag.FCUserID = Session["UserID"].ToString();
            return(View(choicer));
        }
예제 #2
0
        public ActionResult SaveDatabase(int[] IDs)
        {
            if (IDs != null)
            {
                //var countOfRows = db.WTests.Count();

                //var lastRow = db.WTests.Skip(countOfRows - 1).FirstOrDefault();
                // var last = db.WTests.LastOrDefault();



                Choicer Ct = new Choicer();

                for (int j = 0; j < IDs.Length; j++)
                {
                    var id = IDs[j];
                    var r  = (from t in db.Choicers
                              where t.ChoicerID == id
                              select t).FirstOrDefault();
                    Ct.CQuestion      = r.CQuestion;
                    Ct.CAnswer        = r.CAnswer;
                    Ct.Score          = r.Score;
                    Ct.AdditionalInfo = r.AdditionalInfo;
                    Ct.FCUserID       = userid; //Wr.FWuserid=Session["userID"]


                    db.Choicers.Add(Ct);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index", "Choicer"));
            }
            return(View());
        }
예제 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Choicer choicer = db.Choicers.Find(id);

            db.Choicers.Remove(choicer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public void When_FoundNewDevice_then_returnNothing()
        {
            IEnumerable <DeviceToChoice> cache = AnyCache();
            Choicer choicer = new Choicer(cache);

            Device device = choicer.Choice(new StandardChoicer());

            Assert.That(device, Is.Null);
        }
        public void When_FoundNewDevice_then_returnThisDevice()
        {
            IEnumerable <DeviceToChoice> cache = AnyCache();
            Choicer choicer = new Choicer(cache);

            Device device = choicer.Choice(new PremiumChoicer());

            Assert.That(device.Id, Is.EqualTo(cache.First(x => x.Class == DeviceClass.Premium).Id));
        }
예제 #6
0
        // GET: Choicer/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Choicer choicer = db.Choicers.Find(id);

            if (choicer == null)
            {
                return(HttpNotFound());
            }
            return(View(choicer));
        }
예제 #7
0
        public ActionResult Edit([Bind(Include = "ChoicerID,FCategoryID,FCUserID,CQuestion,Opt1,Opt2,Opt3,Opt4,Opt5,CAnswer,IsShareOnline,IsFavourite,IsSkip,Appearance,WAppearance,Score,AdditionalInfo")] Choicer choicer, bool chkShare)
        {
            if (ModelState.IsValid)
            {
                ViewBag.chkShare = chkShare;
                if (chkShare)
                {
                    choicer.IsShareOnline = true;
                }
                else
                {
                    choicer.IsShareOnline = false;
                }
                choicer.FCUserID = userid;

                ViewBag.FCategoryID     = new SelectList(db.Categories, "CategoryID", "Name", choicer.FCategoryID);
                db.Entry(choicer).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            //  ViewBag.FCUserID = new SelectList(db.Users, "UserID", "Forename", choicer.FCUserID);
            return(View(choicer));
        }
예제 #8
0
        // GET: Choicer/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Choicer choicer = db.Choicers.Find(id);

            if (choicer.IsShareOnline == true)
            {
                ViewBag.chkShare = true;
            }
            else
            {
                ViewBag.chkShare = false;
            }
            if (choicer == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FCategoryID = new SelectList(db.Categories, "CategoryID", "Name", choicer.FCategoryID);
            //  ViewBag.FCUserID = new SelectList(db.Users, "UserID", "Forename", choicer.FCUserID);
            return(View(choicer));
        }
예제 #9
0
        // WTest start tomorrow, send data to answer view wothout timer
        public ActionResult Answer(int?id)
        {
            var r = (from t in db.CTests
                     where t.FCTuserID == userid
                     orderby t.CTestID descending
                     select t).First();
            double time   = Convert.ToDouble(r.Score);
            bool   minute = r.TestTime ?? false;
            bool   second = r.TimePerWord ?? false;

            if (minute == true)
            {
                if (Session["EndDate"] == null)
                {
                    Session["EndDate"] = DateTime.Now.AddMinutes(time).ToString("dd-MM-yyyy h:mm:ss tt");
                }
            }
            else if (second == true)
            {
                Session["EndDate"] = DateTime.Now.AddSeconds(time).ToString("dd-MM-yyyy h:mm:ss tt");
            }
            // Session["EndDate"] = DateTime.Now.AddMinutes(minute).ToString("dd-MM-yyyy h:mm:ss tt");

            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            ViewBag.EndDate = Session["EndDate"];
            int value = id ?? default(int);

            if (value == 1)
            {
                int        wid = fwords[true_count];
                ChoiceTest wt  = db.ChoiceTests.Where(t => (t.FChoicerID == wid) && (t.FCTestID == r.CTestID)).FirstOrDefault();
                wt.Result = true;
                db.SaveChanges();
                true_count = true_count + 1;
            }


            // var d = db.WordTests.Where(t => t.FWtestID==1).FirstOrDefault();  // working

            //int turnfirst = 0;
            if (turnfirst == 0)
            {
                v = 0;
                //testid = (from t in db.WTests
                //          orderby t.WTestID descending
                //          select t.WTestID).First();
                Choicer w   = new Choicer();
                var     IDs = db.ChoiceTests.Where(t => t.FCTestID == r.CTestID).ToArray().Select(t => t.FChoicerID);

                int index = 0;
                k = IDs.Count();  // k = total no words
                foreach (var c in IDs)
                {
                    w = db.Choicers.Find(c);
                    if (w.CAnswer == 1)
                    {
                        definitions[index] = w.Opt1.ToString();
                    }
                    else if (w.CAnswer == 2)
                    {
                        definitions[index] = w.Opt2.ToString();
                    }
                    else if (w.CAnswer == 3)
                    {
                        definitions[index] = w.Opt3.ToString();
                    }
                    else if (w.CAnswer == 4)
                    {
                        definitions[index] = w.Opt4.ToString();
                    }
                    else if (w.CAnswer == 5)
                    {
                        definitions[index] = w.Opt5.ToString();
                    }
                    //definitions[index] = w.CAnswer.ToString(); // CAnswer is int so convert into string
                    hint[index]     = w.Category.Name;  // Appearance colomn replace the hint and convert into string
                    wordlist[index] = w.CQuestion;
                    fwords[index]   = w.ChoicerID;
                    index           = index + 1;
                }
                turnfirst = 1;
            }
            if (v < k)
            {
                ViewBag.Definition = definitions[v];
                ViewBag.Hint       = hint[v];
                ViewBag.Word       = wordlist[v];
                v = v + 1;
            }
            else
            {
                ViewBag.Status  = "complete";
                ViewBag.EndDate = null;
                return(RedirectToAction("Result", new { id = r.CTestID }));
            }
            return(View());
        }