public void SetLive(string value) { using (var context = new TourAgencyContext()) { var str = context.LivesString.ToList(); context.LivesString.RemoveRange(str); context.SaveChanges(); context.LivesString.Add(new Live() { LiveString = value }); context.SaveChanges(); } }
// DELETE api/<controller>/5 public void Delete(long id) { using (var context = new TourAgencyContext()) { context.User.Find(id).IfNotNull(x => context.User.Remove(x)); context.SaveChanges(); } }
// DELETE api/<controller>/5 public void Delete(long id) { using (var context = new TourAgencyContext()) { var dbNews = context.NewsModel.Find(id); if (dbNews == null) { return; } context.NewsModel.Remove(dbNews); context.SaveChanges(); } }
// DELETE api/<controller>/5 public void Delete(long id) { using (var context = new TourAgencyContext()) { var dbTest = context.Test.Find(id); if (dbTest == null) { return; } context.Test.Remove(dbTest); context.SaveChanges(); } }
public bool SetVoit([FromUri] string title, [FromUri] int indexId) { try { using (var context = new TourAgencyContext()) { var a = context.Test.FirstOrDefault(f => f.Question == title); if (a == null) { return(false); } var models = new List <AnswerModel>(); try { models = JsonConvert.DeserializeObject <List <AnswerModel> >(a.Answer) ?? new List <AnswerModel>(); } catch (Exception e) { } var model = models.FirstOrDefault(f => f.TitleTest == title); if (model == null) { model = new AnswerModel(); model.TitleTest = title; model.IndexAnswer = indexId; model.Voits = 1; models.Add(model); a.Answer = JsonConvert.SerializeObject(models); context.Test.AddOrUpdate(a); } else { model.Voits++; a.Answer = JsonConvert.SerializeObject(models); context.Test.AddOrUpdate(a); } context.SaveChanges(); return(true); } } catch { return(false); } }
public string Install() { try { using (TourAgencyContext context = new TourAgencyContext()) { context.LanguageModels.AddRange(new List <LanguageModel>() { new LanguageModel() { Name = "Русский", CodeLang = "RU", IsActive = true }, new LanguageModel() { Name = "Aнглиский", CodeLang = "EN", IsActive = false }, new LanguageModel() { Name = "Китайский", CodeLang = "CN", IsActive = false } }); context.TerminalsModels.Add(new TerminalsModel() { TerminalId = Guid.Parse("0f8fad5b-d9cb-469f-a165-70867728950e"), Name = "LoacalHost", IsAutorizate = true }); // сохраняем context.SaveChanges(); } return("Ок"); } catch (Exception e) { return(e.ToString()); } }
// POST api/<controller> public long Post([FromBody] Test value) { using (var context = new TourAgencyContext()) { var dbTest = new StorageAPI.Models.Database.Test() { Answer = String.Empty, Question = value.Question, Responses = JsonConvert.SerializeObject(value.Responses), Title = value.Title, Lang = value.Lang, }; context.Test.Add(dbTest); context.SaveChanges(); return(dbTest.Id); } }
public long Put([FromUri] long id, [FromBody] ExtendedUser value) { using (var context = new TourAgencyContext()) { var dbUser = context.User.Find(id); if (dbUser == null) { return(-1); } dbUser.Name = value.Name; dbUser.Password = value.PasswordHash; context.SaveChanges(); return(dbUser.Id); } }
// POST api/<controller> public long Post([FromBody] News value) { using (var context = new TourAgencyContext()) { var dbNews = new NewsModel { AdvertisingImageUri = value.AdvertisingImageUri, //Content = value.Content, ContentType = value.ContentType, IconUri = value.IconUri, Text = value.Text }; context.NewsModel.Add(dbNews); context.SaveChanges(); return(dbNews.Id); } }
// PUT api/<controller>/5 public long Put(long id, [FromBody] Test value) { using (var context = new TourAgencyContext()) { var dbTest = context.Test.Find(id); if (dbTest != null) { dbTest.Answer = value.Answer; dbTest.Question = value.Question; dbTest.Responses = JsonConvert.SerializeObject(value.Responses); dbTest.Title = value.Title; dbTest.Lang = value.Lang; context.SaveChanges(); return(dbTest.Id); } } return(-1); }
// PUT api/<controller>/5 public long Put(long id, [FromBody] News value) { using (var context = new TourAgencyContext()) { var dbNews = context.NewsModel.Find(id); if (dbNews != null) { dbNews.AdvertisingImageUri = value.AdvertisingImageUri; //dbNews.Content = value.Content; dbNews.ContentType = value.ContentType; dbNews.IconUri = value.IconUri; dbNews.Text = value.Text; context.SaveChanges(); return(dbNews.Id); } } return(-1); }
// POST api/<controller> public long Post([FromBody] ExtendedUser value) { using (var context = new TourAgencyContext()) { if (context.User.Any(x => x.Login == value.Login)) { return(-1); } StorageAPI.Models.Database.User user = new Models.Database.User { Login = value.Login, Name = value.Name, Password = value.PasswordHash }; context.User.Add(user); context.SaveChanges(); return(user.Id); } }
public long TestResultAdd([FromBody] AccomplishedTestParams value) { using (var context = new TourAgencyContext()) { if (!context.User.Any(x => x.Id == value.UserId) && !context.Test.Any(x => x.Id == value.TestId)) { return(-1); } var testRecord = new User_Test { UserId = value.UserId, TestId = value.TestId, Result = value.Result, PassingStamp = DateTime.Now }; context.User_Test.Add(testRecord); context.SaveChanges(); return(testRecord.UserId); } }
public bool Save() { return(db.SaveChanges() > 0); }
public void Save() { db.SaveChanges(); }
public void Save() { _context.SaveChanges(); }