예제 #1
0
        public ActionResult AddOrEdit(int? id)
        {
            var model = new NewsViewModel();
            if (id.HasValue)
            {
                var item = Db.Get<News>(id.Value);
                model = Mapper.Map(item, model);
            }

            return View(model);
        }
예제 #2
0
        public ActionResult Index(int id)
        {
            var model = new NewsViewModel();

            var item = Db.Get<News>(id);
            if (item == null)
            {
                return View("ServerError", (object)"Страница не найдена");
            }
            model = Mapper.Map(item, model);

            return View(model);
        }
예제 #3
0
        public ActionResult AddOrEdit(NewsViewModel model)
        {
            //найдём пользователя в БД
            var userFromDb = Db.Where<User>(u => u.Email == UserInfo.Email).FirstOrDefault();
            if (userFromDb != null)
            {
                var item = new News();
                if (model.Id > 0)
                {
                    item = Db.Get<News>(model.Id);
                }
                item = Mapper.Map(model, item);

                item.LogDate = DateTime.Now;
                item.User = new User { Id = userFromDb.Id };

                var result = Db.SaveOrUpdate(item);

                return RedirectToAction("List");
            }
            return View("ServerError", (object)"Не удалось определить пользователя");
        }