public void AddMessage(MessageModel model)
        {
            Provider.Execute(@"insert into Messages(Title, Body, UserId, GuestBookId) values(@szTitle, @szBody, null, @szGuestBookId)"
                , new {szTitle = model.Title, szBody = model.Body, szGuestBookId = model.GuestBook.GuestBookId}
                , CommandType.Text);

        }
Exemple #2
0
        public void ModelValidateTestFalse()
        {
            var model = new MessageModel();
            model.UpdateDate = DateTime.Now.AddDays(-1);
            model.Title = "title";
            model.Body = "body";
            TestContextController controller = new TestContextController();
            var result = controller.TestTryValidateModel(model);

            Assert.IsFalse(result);

            var state = controller.ModelState;
            Assert.IsFalse(state.IsValid);


        }
Exemple #3
0
        public void ModelValidateTestOk()
        {
            var model = new MessageModel();
            model.UpdateDate = DateTime.Now.AddDays(1);
            model.Title = "title";
            model.Body = "body";
            model.Weight = (decimal) 1;
            model.WeightDouble = (decimal?) 2.12;
            TestContextController controller = new TestContextController();
            var result = controller.TestTryValidateModel(model);

            Assert.IsTrue(result);

            var state = controller.ModelState;
            Assert.IsTrue(state.IsValid);


        }
        public virtual ActionResult Edit( MessageModel message)
        {
            bool isValid = true;
            if (!ModelState.IsValidField("Title"))
            {
                ModelState.AddModelError("Title", "Необходимо ввести заголовок сообщения");
                isValid = false;
            }

            if (!ModelState.IsValidField("Body"))
            {
                ModelState.AddModelError("Body", "Необходимо ввести сообщение");
                isValid = false;
            }

            if (isValid)
            {
                
                try
                {
                    DataService.AddMessage(message);
                    return RedirectToAction(MVC.Home.ActionNames.Index, MVC.Home.Name, new {id=message.GuestBook.GuestBookId});
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e);
                }
                
            }
            var gbooks = DataService.LoadGuestBooks();
            return View(MVC.Home.Views.Edit, new EditMessageModelView()
            {
                Message = message,
                GuestBooks = gbooks
            });
        }
 public EditMessageModelView()
 {
     Message=new MessageModel();
     GuestBooks = new GuestBookModel[]{};
 }