public ActionResult Add(News news) { var user = YandexAuth.GetUser(Request); //найдём пользователя в БД var list = MvcApplication.Db.Where<User>(u => u.Login == user.display_name); if (list.Any()) { news.LogDate = DateTime.Now; news.User = new User {Id = list.FirstOrDefault().Id}; var result = MvcApplication.Db.Save(news); return RedirectToAction("Single", new {newsId = result}); } return RedirectToAction("Index", "Home"); }
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)"Не удалось определить пользователя"); }
public ActionResult Export(FileViewModel file) { var csvLines = System.IO.File.ReadAllLines(Server.MapPath("~/Upload/Temp/news.csv")); var siteUrl = "http://localhost:3893"; var erorrs = ""; for (int i = 0; i < csvLines.Length; i++) { var line = csvLines[i]; var t = line.Split(new[] {"\";\""}, StringSplitOptions.None); if (t.Count() != 5) { erorrs += i + ","; continue; } var news = new News { Title = t[0].Substring(1), Resume = t[1] .Replace("/sites/default/files/styles/large/public/images", siteUrl + "/Upload/Images") .Replace("/sites/default/files", "/Upload/Files") .Replace("http://box9-vlg.ru", siteUrl) .Replace("\"\"", "\""), Body = t[2] .Replace("/sites/default/files/styles/large/public/images", siteUrl + "/Upload/Images") .Replace("/sites/default/files", "/Upload/Files") .Replace("http://box9-vlg.ru", siteUrl) .Replace("\"\"", "\""), LogDate = UnixTimeStampToDateTime(Convert.ToDouble(t[3])), User = new User {Id = 2} }; var result = Db.SaveOrUpdate(news); } return View(); }