public string Index(string id = "5a1caf8e-1cbc-42f7-ae66-6a22718c9e57") { using (var db = new VCardsEntities()) { var guid = Guid.Empty; Guid.TryParse(id, out guid); var user = db.Users.Where(_ => _.SocialId == guid).FirstOrDefault(); if (user == null) { db.Users.Add(new User() { LastUpdate = DateTime.UtcNow, Points = 0, Tocken = Guid.NewGuid(), SocialId = guid, UILanguage = "en"}); } try { db.SaveChanges(); } catch (Exception ex) { return ex.StackTrace + ex.InnerException.StackTrace; } return "OK"; } }
public string PutWord(int userId, string word, string translate, int id = 0, string ugid = "5a1caf8e-1cbc-42f7-ae66-6a22718c9e57") { using (var db = new VCardsEntities()) { var guid = Guid.Empty; Guid.TryParse(ugid, out guid); var user = db.Users.Where(_=>_.SocialId == guid).FirstOrDefault(); Word word1 = null; if (user != null) { word1 = new Word() {Word1 = word, Translation = translate, ModifyDate = DateTime.UtcNow, Uid = Guid.NewGuid()}; word1.UserId = user.Id; db.Words.Add(word1); } try { db.SaveChanges(); } catch (Exception ex) { return ex.StackTrace + ex.InnerException.StackTrace; } return "OK"; } }
public ActionResult AllMyWords() { List<ViewWordModel> wordsList = new List<ViewWordModel>(); using (var db = new VCardsEntities()) { int userId = Convert.ToInt32(User.Identity.Name); var resultList = db.Words.Where(x => x.UserId == userId); foreach (var word in resultList) { wordsList.Add(new ViewWordModel() { Word = word.Word1, Translation = word.Translation }); } } return View(wordsList); }
public ActionResult AddTag(string tag) { string returnUrl = Request.UrlReferrer.AbsolutePath; if(!String.IsNullOrEmpty(tag)) { using (VCardsEntities db = new VCardsEntities()) { int userId = Convert.ToInt32(User.Identity.Name); if (db.Tags.FirstOrDefault(x => x.UserId == userId && x.Tag1 == tag) == null) { Tag tagAdd = new Tag(); tagAdd.UserId = userId; tagAdd.Tag1 = tag; db.Tags.Add(tagAdd); db.SaveChanges(); } } } return Redirect(returnUrl); }
public JsonResult GetWord(string id = "5a1caf8e-1cbc-42f7-ae66-6a22718c9e57") { using (var db = new VCardsEntities()) { IEnumerable<Word> result = new List<Word>(); var guid = Guid.Empty; Guid.TryParse(id, out guid); var user = db.Users.Where(_=>_.SocialId == guid).FirstOrDefault(); if (user != null) { result = db.Words.Where(_=>_.UserId == user.Id).ToArray(); if (result.Count()!=0) { var res = result.Select(_ => new {word = _.Word1, translate = _.Translation}); return Json(res, JsonRequestBehavior.AllowGet); } } return Json(result, JsonRequestBehavior.AllowGet); } }
public ActionResult ChangeCulture(string lang, int id) { string returnUrl = Request.UrlReferrer.AbsolutePath; // Список культур List<string> cultures = new List<string>() { "ru", "en" }; if (!cultures.Contains(lang)) { lang = "ru"; } // Сохраняем выбранную культуру в куки HttpCookie cookie = Request.Cookies["lang"]; if (cookie != null) cookie.Value = lang; // если куки уже установлено, то обновляем значение else { cookie = new HttpCookie("lang"); cookie.HttpOnly = false; cookie.Value = lang; cookie.Expires = DateTime.Now.AddYears(1); } Response.Cookies.Add(cookie); using (VCardsEntities db = new VCardsEntities()) { var user1 = db.Users.FirstOrDefault(x=> x.Id == id); if (user1 != null) user1.UILanguage = lang; db.SaveChanges(); FormsAuthentication.SetAuthCookie(id.ToString(), false); } return Redirect(returnUrl); }
public ActionResult Words(AddWordModel newWord) { ViewBag.Message = "Your app description page."; if(ModelState.IsValid) { using (var db = new VCardsEntities()) { db.Words.Add(new Word() { FailsCount = 0, SucceedsCount = 0, IsIdiom = false, ModifyDate = DateTime.UtcNow, Word1 = newWord.Word, Translation = newWord.Translation, Uid = Guid.NewGuid(), UserId = 1 }); db.SaveChanges(); } } return View(newWord); }
public ActionResult Index() { ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application."; using (var db = new VCardsEntities()) { var T = db.Tags.FirstOrDefault(); } return View(); }
public ActionResult Contact() { ViewBag.Message = "Your contact page."; using (VCardsEntities db = new VCardsEntities()) { var user1 = db.Users.Include("Tags").FirstOrDefault(); if (user1 != null) { return View(new Models.User() { Language = user1.LastName, Name = user1.Name, TagList = user1.Tags, Id = user1.Id }); } } return View(new Models.User()); }