示例#1
0
 public virtual ActionResult Create(CreateProblemVM problemVM)
 {
     if (ModelState.IsValid)
     {
         // create new problem
         Problem p = new Problem();
         p.UserId = _authenticationService.GetUserId();
         p.Title = problemVM.Title;
         p.Content = problemVM.Content;
         p.DateCreated = DateTime.Now;
         p.DateModified = DateTime.Now;
         bool res = _problemCommandService.AddProblem(p);
         if (!res)
         {
             // by some reason. cannot create problem
             ModelState.AddModelError("create_problem_exception", "This problem cannot be created. Try again later");
             return View("Views/CreateProblem", problemVM);
         }
         else
         {
             return Detail(p.Id);
         }
     }
     else
     {
         // if not ModelState valid
         ModelState.AddModelError("model_state_invalid", "Current State is Invalid");
         return View("Views/CreateProblem", problemVM);
     }
 }
示例#2
0
        public void TestGeneralProblem()
        {
            IProblemCommandService problemCommandService =
                ObjectFactory.GetInstance<IProblemCommandService>();
            IProblemQueryService problemQueryService =
                ObjectFactory.GetInstance<IProblemQueryService>();
            IRepository<Problem> problemRepository =
                ObjectFactory.GetInstance<IRepository<Problem>>();

            bool res;

            User u = ProblemPreaparation.u;

            // create problem
            Problem p = new Problem();
            p.Title = "Console Problem Test One";
            p.Content = "This is a hard hard problem";
            p.DateCreated = DateTime.Now;
            p.DateModified = DateTime.Now;
            p.UserId = u.Id;
            res = problemCommandService.AddProblem(p);
            Assert.IsTrue(res);
            Assert.IsTrue(p.Id > 0);

            // retrieve problem
            Problem np = problemQueryService.GetProblemById(p.Id);
            Assert.AreEqual(np.Title, p.Title);
            Assert.AreEqual(np.Content, np.Content);

            // update problem
            p.Title = "New Problem Title";
            p.Content = "New Content. Ya";
            res = problemCommandService.UpdateProblem(p);
            Problem nps = problemQueryService.GetProblemById(p.Id);
            Assert.AreEqual(p.Id, nps.Id);
            Assert.AreEqual(p.Title, np.Title);
            Assert.AreEqual(p.Content, nps.Content);
            Assert.AreEqual(p.Title, "New Problem Title");

            // delete problem
            problemCommandService.DeleteProblem(np);
            Assert.IsNull(problemQueryService.GetProblemById(p.Id));

            ProblemPreaparation.CleanUp();
        }
示例#3
0
        public static void Preparation()
        {
            StructureMapOfflineConfg.Configure();
            IUserCommandService userCommandService =
                ObjectFactory.GetInstance<UserCommandService>();
            IProblemCommandService problemCommandService =
                ObjectFactory.GetInstance<ProblemCommandService>();
            ITagCommandService tagCommandService =
                ObjectFactory.GetInstance<TagCommandService>();
            // create a user
            u = new User();
            u.Username = "******";
            u.Score = 0;
            userCommandService.InsertUser(u, null, null);
            Assert.IsTrue(u.Id > 0);
            // create an avatar link
            Image img = new Image();
            img.Description = "this is a sample url";
            img.Url = "www.google.com";

            // create a new problem
            p = new Problem();
            p.Title = "This is a hard problem";
            p.Content = "This problem is so hard";
            p.DateCreated = DateTime.Now;
            p.DateModified = DateTime.Now;
            p.UserId = u.Id;
            problemCommandService.AddProblem(p);
            Assert.IsTrue(p.Id > 0);

            // create custom tag
            t = new Tag();
            t.Name = "Combinatoric";
            t.Description = "this is a hard tag";
            t.CreatorId = u.Id;
            t.DateCreated = DateTime.Now;
            t.DateModified = DateTime.Now;
            tagCommandService.CreateNewTag(t);
        }
示例#4
0
 public bool DeleteProblem(Problem problem)
 {
     return problemRepository.Delete(problem);
 }
示例#5
0
 public bool AddProblem(Problem problem)
 {
     return problemRepository.Insert(problem);
 }
示例#6
0
 public bool UpdateProblem(Problem problem)
 {
     return problemRepository.Update(problem);
 }