public async Task <UrlInfo> Get(int id) { using (var context = new TourAgencyContext()) { return(await context.UrlInfos.Include(r => r.UrlListInfos).FirstOrDefaultAsync(r => r.ButtonId == id)); } }
public async Task <Information> GetId(int id) { using (var context = new TourAgencyContext()) { return(await context.Information.FirstOrDefaultAsync(r => r.Id == id)); } }
public async Task <List <StorageAPI.Models.Database.Slider> > Get() { using (var context = new TourAgencyContext()) { return(await context.Slider.ToListAsync()); } }
public async Task <List <Information> > GetIdSection(int id) { using (var context = new TourAgencyContext()) { try { Section elm = await context.Sections.Include(r => r.Disciples).FirstOrDefaultAsync(r => r.Id == id); if (elm != null) { return(elm.Disciples.Where(r => r.IsPublick == true).Select(z => new Information() { Id = z.Id, DateTime = z.DateTime, SectionsId = z.SectionsId, Info = z.Info, Title = z.Title }).ToList()); } } catch (Exception el) { } return(null); } }
public EFUnitOfWork(string connectionString) { db = new TourAgencyContext(connectionString); userManager = new UserManager(new UserStore <User>(db)); roleManager = new UserRoleManager(new RoleStore <UserRole>(db)); clientManager = new ClientManager(db); }
// 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(); } }
// GET api/<controller> public IEnumerable <Test> Get(int limit, int offset) { limit %= 1000; using (var context = new TourAgencyContext()) { var test = context.Test.ToList().Select(Test.CreateFromDb); return(context.Test.ToList().Select(Test.CreateFromDb)); } }
public async Task <Information> Get(int id) { using (var context = new TourAgencyContext()) { return(await context.Information.FirstOrDefaultAsync(r => r.ButtonId == id && string.IsNullOrEmpty(r.Cat) && r.IsPublick)); } }
public async Task <IEnumerable <NewsModel> > Get(DataComModel model) { using (var context = new TourAgencyContext()) { return(await context.NewsModel .AsNoTracking() .Where(r => r.Language == model.Language) .ToListAsync()); } }
public async Task <List <PassageImage> > Get(int id) { using (var context = new TourAgencyContext()) { return(await context.PassageImages .AsNoTracking() .Include(r => r.imageLists) .Where(r => r.ButtonId == id) .ToListAsync()); } }
// GET api/<controller>/5 public Test Get(long id) { using (var context = new TourAgencyContext()) { var dbTest = context.Test.Find(id); if (dbTest != null) { return(Test.CreateFromDb(dbTest)); } } return(null); }
public string GetFirstBisy() { using (var context = new TourAgencyContext()) { try { return(context.VideoConnects.FirstOrDefault(f => !f.IsBusy)?.Name); } catch { return(null); } } }
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(); } }
public ExtendedUser Get([FromUri] long id) { using (var context = new TourAgencyContext()) { var dbUser = context.User.Find(id); if (dbUser != null) { return(StorageAPI.Models.ExtendedUser.CreateFromDbWithTests(dbUser)); } } return(null); }
public User Auth([FromUri] string login, [FromUri] string password) { using (var context = new TourAgencyContext()) { var hash = Convert.ToBase64String(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(password))); var dbUser = context.User.FirstOrDefault(x => x.Login == login && x.Password == hash); if (dbUser != null) { return(StorageAPI.Models.User.CreateFromDb(dbUser)); } } return(null); }
// 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 async Task <List <Information> > GetLents(int id) { try { using (var context = new TourAgencyContext()) { return(await context.Information.Where(r => r.ButtonId == id && r.Cat == "ListModel" && r.IsPublick == true).ToListAsync()); } } catch { return(null); } }
public async Task <string> GetVideoGuide() { try { using (var context = new TourAgencyContext()) { VideoGuideModel elm = await context.VideoGuideModels.FirstOrDefaultAsync(); if (elm != null) { return(elm.Path); } } } catch { } return(string.Empty); }
public async Task <List <Section> > Get(int id) { List <Section> list = null; using (var context = new TourAgencyContext()) { list = await context.Sections.Include(r => r.Children).Where(r => r.ButtonId == id).ToListAsync(); for (int i = 0; i < list.Count; i++) { list[i].Disciples = null; LoadSection(list[i].Children); } } return(list); }
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()); } }
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 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] 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); } }
// 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); } }
public async Task CallEnd(string name) { using (var context = new TourAgencyContext()) { try { var admin = context.VideoConnects.FirstOrDefault(f => f.Name == name); if (admin == null) { return; } admin.IsBusy = false; await context.SaveChangesAsync(); } catch (Exception e) { } } }
public async Task AdminLeave(string name) { using (var context = new TourAgencyContext()) { try { var admin = context.VideoConnects.FirstOrDefault(f => f.Name == name); if (admin == null) { return; } context.VideoConnects.Remove(admin); await context.SaveChangesAsync(); } catch { } } }
public async Task <bool> AddNewAdmin(string name) { using (var context = new TourAgencyContext()) { try { VideoConnect admin = new VideoConnect(); admin.Name = name; admin.IsBusy = false; context.VideoConnects.Add(admin); await context.SaveChangesAsync(); return(true); } catch { return(false); } } }
// 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); }