示例#1
0
        //[TestMethod]
        public void TestIsVaild()
        {
            var t1 = new Teacher() { Name = "Erik Jacobsen", Username = "******", Password = "******" };
            var t2 = new Teacher() { Name = "Karsten", Username = "******", Password = "******" };

            // Does not work, since IsValid looks in the db
            //Assert.IsTrue(t1.IsValid("eaaej", "russia"));
            //Assert.IsFalse(t2.IsValid("eaakk", "go"));
        }
        public ActionResult Login(Teacher model)
        {
            if (model.IsValid(model.Username, model.Password))
            {
                FormsAuthentication.SetAuthCookie(model.Username, true);
                return RedirectToAction("Demo");
            }
            else
            {
                ModelState.AddModelError("", "Login is invalid");
            }

            return View(model);
        }
示例#3
0
        public bool AddLessonBlock(Teacher t, Subject s, int blocksCount)
        {
            // Check whether or not this subject is full already.
            if (!IsSubjectFull(s,blocksCount)) {
                // Check if there are a SubjectDistBlock with this subject AND this teacher already! If there are - add to the blockscount! :-)
                SubjectDistBlock sdb = (from sb in SubjectDistBlocks
                                       where sb.Subject.Equals(s) && sb.Teacher.Equals(t)
                                       select sb).FirstOrDefault();

                if (sdb != null)
                {
                    // Already exists!
                    sdb.BlocksCount += blocksCount;
                }
                else
                {
                    // Create new!
                    SubjectDistBlocks.Add(new SubjectDistBlock { Teacher = t, Subject = s, BlocksCount = blocksCount });
                }
                return true;
            }
            return false;
        }