예제 #1
0
        public IActionResult Edit(int id, Message model)
        {
            var message = _messages.GetBy(id);
            if (message == null)
            {
                return HttpNotFound();
            }

            if (message.UserId != User.GetUserId())
            {
                return HttpUnauthorized();
            }

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            message.MessageTitle = model.MessageTitle;
            message.MessageContent = model.MessageContent;

            _messages.Update(message);

            return RedirectToAction("index");

        }
        public IActionResult Create(Message model)
        {
            // todo: validate


            // todo: store

            return RedirectToAction("index");
        }
        public IActionResult Create(Message model)
        {
            // todo: validate
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // todo: store

            return RedirectToAction("index");
        }
예제 #4
0
        public IActionResult Create(Message model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            model.Created = DateTime.Now;
            model.UserId = User.GetUserId();

            _messages.Add(model);

            return RedirectToAction("index");
        }
        public IActionResult Edit(int id)
        {
            // todo: retrieve message
            var message = new Message
            {
                MessageTitle = "A sample message",
                MessageContent = "This the content"
            };

            if (message == null)
            {
                return HttpNotFound();
            }

            return View(message);
        }
        public IActionResult Edit(int id, Message model)
        {
            // todo: retrieve message
            var message = new Message();

            if (message == null)
            {
                return HttpNotFound();
            }

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // todo: update and store
            message.MessageTitle = model.MessageTitle;
            message.MessageContent = model.MessageContent;


            return RedirectToAction("index");
        }
 public void Add(Message message)
 {
     message.Id = GetNextId();
     Messages.Add(message);
 }
 public void Update(Message message)
 {
     // TODO: nothing
 }