public static void ConnectToDocumentDB(TestContext context) { var documentDbConnectionData = GetDocumentDBConnectionData(); var endpoint = documentDbConnectionData["endpoint"]; var authKey = documentDbConnectionData["authkey"]; docDBRepo = new DocumentDBRepository<Product>( endpoint, authKey, DatabaseId, CollectionId); }
public static void Init(TestContext context) { _endpoint = ConfigurationManager.AppSettings["endpoint"]; _authKey = ConfigurationManager.AppSettings["authKey"]; _database = ConfigurationManager.AppSettings["database"]; _collection = ConfigurationManager.AppSettings["collection"]; _performanceLevel = ConfigurationManager.AppSettings["performanceLevel"]; _repository = DocumentDBRepository<Customer>.Create(_endpoint, _authKey, _database, _collection, _performanceLevel); }
static void Main(string[] args) { string endpoint = "test"; string authKey = "test"; var connectionPolicy = new Microsoft.Azure.Documents.Client.ConnectionPolicy() { ConnectionMode = Microsoft.Azure.Documents.Client.ConnectionMode.Direct, ConnectionProtocol = Microsoft.Azure.Documents.Client.Protocol.Tcp }; var repo = new DocumentDBRepository<TestDocument>(endpoint, authKey, "DataPointsReportsDatabase", "TestRepo", 2, u => ((TestDocument)u).PartitionKey, connectionPolicy); Console.WriteLine("Repository created: 2 collections used."); // Keep the self links in memory to be able to delete them in the end. List<string> recordSelfLinks = new List<string>(); for (int i = 0; i < 50; i++) { var insert = new TestDocument() { TestProp = "testDoc" + i, PartitionKey = (i % 4).ToString() }; recordSelfLinks.Add(repo.InsertItemAsync(insert).Result.SelfLink); } Console.WriteLine("50 records added with 4 partition keys."); // Get all records from the collections where partition keys 0 and 1 are assigned to. var allResults = repo.Get(x => (x.PartitionKey == "0" || x.PartitionKey == "1")); Console.WriteLine(string.Format("Number of records in collections with partitions 0 and 1: {0}", allResults.Count())); // We need to pass a predicate as well. // Otherwise we will get all records from the collection where // partitions with a value of "0" are assigned to by the partitioner. var allRecordsByFirstPartition = repo.Get((x => x.PartitionKey == "0"), null, new TestDocument() { PartitionKey = "0" }).ToList(); Console.WriteLine(string.Format("Number of records with partitionKey 0: {0}", allRecordsByFirstPartition.Count())); bool success = true; foreach (var selfLink in recordSelfLinks) { success = success & repo.DeleteAsync(selfLink).Result; } Console.WriteLine(string.Format("Records deleted successfully: {0}", success)); Console.ReadLine(); }
private static async Task <string> GetManagerId(Employee employee) { var managerId = employee.ManagerEmailId ?? employee.DemoManagerEmailId; var manager = await DocumentDBRepository.GetItemAsync <Employee>(managerId); if (manager != null) { return(manager.UserUniqueId); } else { return(null); } }
public async Task <ActionResult> Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Movie movie = await DocumentDBRepository <Movie> .GetItemAsync(id); if (movie == null) { return(HttpNotFound()); } return(View(movie)); }
public async Task <ActionResult> Create([Bind(Include = "Title,Content")] BlogEntryModel item) { if (ModelState.IsValid) { item.ID = string.Empty;// Guid.NewGuid().ToString(); item.CreatedOn = DateTime.Now; item.IsApproved = true; item.ApprovedOn = DateTime.Now; await DocumentDBRepository <BlogEntryModel> .CreateItemAsync(item); return(RedirectToAction("Index")); } return(View(item)); }
private async Task <bool> emailInUse(Result <Email> email) { // Make sure the predicate is comparing the correct objects at the correct level // not the wrapper or result var custs = await DocumentDBRepository <Customer> .GetItemsAsync(cust => cust.Email.Value == email.Value); if (custs.Count() > 0) { return(true); } else { return(false); } }
public async Task <string> ReadBEmail(string templateName, string bridgeModule) { var be = await DocumentDBRepository.GetItemsAsync <BEmail>(d => d.TemplateName.ToLower() == templateName.ToLower() && d.BridgeModule == bridgeModule && d.Tag == "BEmail"); if (be == null) { //throw a meaningful exception or give some useful feedback to the user! return("User not found"); } //ViewBag.BEmailInfo = be.FirstOrDefault(); return(JsonConvert.SerializeObject(be.FirstOrDefault())); }
public async Task <ActionResult <GameVievItem> > GetGameVievItem(string gameId = null) { IEnumerable <Game> games; if (String.IsNullOrWhiteSpace(gameId)) { games = await DocumentDBRepository <Game> .GetItemsAsync(g => true); } else { games = await DocumentDBRepository <Game> .GetItemsAsync(g => g.Id == gameId); } return(Ok(games.Select(x => x.ToPoco()))); }
public async Task <ActionResult> IndexAsync(string searchString) { string bm = (string)Session["BridgeModule"]; var bioras = await DocumentDBRepository.GetItemsAsync <BIORA>(d => d.Tag == "BIORA" && d.BridgeModule == bm); if (!String.IsNullOrEmpty(searchString)) { searchString = searchString.ToLower(); bioras = bioras.Where(s => (s.BookMarkName + "x").ToLower().Contains(searchString) || (s.Chapter + "x").ToLower().Contains(searchString) || (s.Formula + "x").ToLower().Contains(searchString)); } return(View(bioras.OrderBy(s => s.Chapter))); }
public async Task <ActionResult> CreateAsync() { var j = await DocumentDBRepository <Job> .GetItemAsync("a74571b7-2758-48ae-bd1a-d88efc437f26"); ViewBag.Job = j; var i = await DocumentDBRepository <IORA> .GetItemAsync("290c5999-2076-46f1-b40f-443f42cea4f8"); ViewBag.IORA = i; var f = await DocumentDBRepository <BingFinancial> .GetItemsAsync(d => d.Tag == "BingFinancial" && d.BridgeModule == j.BridgeModule && d.CertType == j.CertType); ViewBag.FinancialSet = f.FirstOrDefault(); var S = new BingIORA(); return(View(S)); }
static private async Task DoWork() { DocumentDBRepository <produce.Models.Feed> .Initialize(); DocumentDBRepository <produce.Models.Item> .Initialize(); //process video to audo, upload to blob, get file properties (length, size) ProcessAndUploadVideo(); //write this new record to DocDB await WriteToDocDB(); //use DocDB to write the RSS Feed await GetRssFeed(); }
public async void Revoke(string refreshToken) { var users = await DocumentDBRepository <User> .GetItemsAsync(u => u.RefreshToken == refreshToken); var user = users.SingleOrDefault(); if (user == null) { throw new NullReferenceException("User does not exist"); } user.UpdateRefreshToken(string.Empty); await DocumentDBRepository <User> .UpdateItemAsync(user.Id, user); }
public async Task TestEditItemsAsync() { var item = new Item { Id = "942b1512-1d1e-4c8a-8199-878bdc0395d8", Student_Number = "21833736", First_Name = "Akhie", Last_Name = "Ishwarlaal", Email = "*****@*****.**", Home_Address = "Suncoast", Mobile = "0767619968", Photo_Path = "http...................", Status = true }; await DocumentDBRepository <Item> .CreateItemAsync(item); var edititem = new Item { Id = "942b1512-1d1e-4c8a-8199-878bdc0395d8", Student_Number = "21833736", First_Name = "Akhil", Last_Name = "Ishwarlaal", Email = "*****@*****.**", Home_Address = "Suncoast", Mobile = "0767619968", Photo_Path = "http...................", Status = true }; // Create the item // update the item await DocumentDBRepository <Item> .UpdateItemAsync(item.Id, edititem); // Query for the item var returnedItem = await DocumentDBRepository <Item> .GetItemAsync(item.Id, item.Student_Number); // Verify the item returned is correct. Assert.AreEqual(edititem.Id, returnedItem.Id); Assert.AreEqual(edititem.Student_Number, returnedItem.Student_Number); Assert.AreEqual(edititem.First_Name, returnedItem.First_Name); Assert.AreEqual(edititem.Last_Name, returnedItem.Last_Name); Assert.AreEqual(edititem.Email, returnedItem.Email); Assert.AreEqual(edititem.Home_Address, returnedItem.Home_Address); Assert.AreEqual(edititem.Mobile, returnedItem.Mobile); Assert.AreEqual(edititem.Photo_Path, returnedItem.Photo_Path); Assert.AreEqual(edititem.Status, returnedItem.Status); }
public static async Task <Patient> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = "Get/{emailId}")] HttpRequest req, ILogger log, string id, string emailId) { log.LogInformation("C# HTTP trigger function to get a single patient data from Cosmos DB"); IDocumentDBRepository <Patient> Respository = new DocumentDBRepository <Patient>(); var patients = await Respository.GetItemsAsync(d => d.Id == id && d.EmailId == emailId, "Patient"); Patient patient = new Patient(); foreach (var emp in patients) { patient = emp; break; } return(patient); }
public async Task <ActionResult> DeleteAsync(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WebsiteProperties item = await DocumentDBRepository <WebsiteProperties> .GetItemAsync(id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
public async Task <IHttpActionResult> UpdateIncident(string IncidentId, Incident newIncident) { var newDocDbIncident = await DocumentDBRepository <Incident> .UpdateItemAsync(IncidentId, newIncident); if (newDocDbIncident == null) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new ApiResponseMsg("Unable to update incident"), ReasonPhrase = "An error occurred" }; throw new HttpResponseException(resp); } return(Ok(newDocDbIncident)); }
public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Item item = (Item)DocumentDBRepository.GetItem(id); if (item == null) { return(this.HttpNotFound()); } return(this.View(item)); }
public async Task <IActionResult> Details(string id, string search = "*", int top = 10, int skip = 0, string orderby = "date") { if (id == null) { return(StatusCode(StatusCodes.Status400BadRequest)); } SpielEntry s = await DocumentDBRepository <SpielEntry> .GetItemAsync(id); ViewData["SearchTop"] = top; ViewData["SearchSkip"] = skip; ViewData["SearchString"] = search; ViewData["searchOrder"] = orderby; return(View(s)); }
public async Task <ActionResult> EditAsync([Bind(Include = "Id,Name,Description,Completed")] Item item) { if (ModelState.IsValid) { await DocumentDBRepository <Item> .UpdateItemAsync(item.Id, item); await this.auditClient.AuditAsync( AuditRequest.AsChangeTo(item, i => i.Id) .AsEvent("EditedItem") .WithData(item, i => i.Id)); return(RedirectToAction("Index")); } return(View(item)); }
public async Task <ActionResult> DeleteAsync(string id) { if (id == null) { return(BadRequest()); } Order order = await DocumentDBRepository <Order> .GetOrderAsync(id); if (order == null) { return(NotFound()); } return(View(order)); }
public ActionResult Edit(string id) { if (string.IsNullOrEmpty(id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var item = (DocDBSite)DocumentDBRepository <DocDBSite> .GetItem(d => d.id == id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
public async Task <HttpResponseMessage> GetAttachmentList(string formId) { try { DocumentDBRepository.Initialize(); List <AttachmentItem> list = await DocumentDBRepository.GetAttachmentList(formId); HttpResponseMessage r = Request.CreateResponse(HttpStatusCode.OK, list); r.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); return(r); } catch { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public async Task <ActionResult> EditAsync([Bind(Include = "Tag,Id,BridgeModule,ProdName,TechParaName," + "Description,ValueSource,DefaultValue,ValueType,ViewSequence")] BProdTechPara item) { if (IsAdmin()) { if (ModelState.IsValid) { await DocumentDBRepository.UpdateItemAsync <BProdTechPara>(item.Id, item); return(RedirectToAction("Index")); } } await SetViewBag(); return(View(item)); }
public async Task <ActionResult> DeleteAsync(string id) { if (id == null) { return(BadRequest()); } LogItem item = await DocumentDBRepository <LogItem> .GetItemAsync(id); if (item == null) { return(NotFound()); } return(View(item)); }
public async Task <ActionResult> DeleteAsync(string id, string category) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Item item = await DocumentDBRepository <Item> .GetItemAsync(id, category); if (item == null) { return(HttpNotFound()); } return(View(item)); }
public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Item item = DocumentDBRepository <Item> .GetItem(x => x.Id == id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
public async Task <String> SetViewBag() { string bm = (string)Session["BridgeModule"]; var lmeditemno = await DocumentDBRepository.GetItemsAsync <BList>(d => d.Tag == "BList" && d.BridgeModule == bm && d.ListType == "MEDItemNo"); lmeditemno = lmeditemno.OrderBy(d => d.ListItem); ViewBag.LMEDItemNo = lmeditemno; var lvalueresource = await DocumentDBRepository.GetItemsAsync <BList>(d => d.Tag == "BList" && d.BridgeModule == bm && d.ListType.ToLower().Contains("blisttype") && (d.ListItem.ToLower().Contains("autocomplete") || d.ListItem.ToLower().Contains("dropdown") || d.ListItem.ToLower().Contains("free text"))); lvalueresource = lvalueresource.OrderBy(d => d.ListItem); ViewBag.LValueResource = lvalueresource; return(""); }
private static async Task AdminEmailId(IDialogContext context, Admin userAdmin) { var existingAdmin = await DocumentDBRepository.GetItemsAsync <Admin>(l => l.Type.Contains(Helper.Constants.SetAdmin)); if (existingAdmin.Count() > 0) { var Admin = existingAdmin.FirstOrDefault(); Admin.EmailId = userAdmin.EmailId; var updateAdmin = await DocumentDBRepository.UpdateItemAsync(Admin.Id, Admin); } else { userAdmin.Type = "Admin"; await DocumentDBRepository.CreateItemAsync <Admin>(userAdmin); } }
public async Task <ActionResult> EditAsync(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Student item = await DocumentDBRepository <Student> .GetItemAsync(id); if (item == null) { return(HttpNotFound()); } return(View(item)); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var isAuthorized = base.AuthorizeCore(httpContext); if (!isAuthorized) { return(false); } else { var documentDb = new DocumentDBRepository <Income>("Income", httpContext.User.Identity.GetUserId()); System.Web.HttpContext.Current.Application["Salary"] = documentDb.GetUserItemAsync(); return(true); } }
public async Task <ActionResult> Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DocReq r = await DocumentDBRepository.GetItemAsync <DocReq>(id); if (r == null) { return(HttpNotFound()); } return(View(r)); }
private static async Task ShowFlightInfo(FlightInputDetails flighinput, Activity replyActivity) { //DateTime local = flighinput.JourneyDate.ToUniversalTime(); var list = await DocumentDBRepository <FlightInfo> .GetItemsAsync(d => d.FromCity == flighinput.From && d.ToCity == flighinput.To);/* && d.JourneyDate.ToShortDateString()==flighinput.JourneyDate.ToShortDateString());*/ if (list.Count() > 0) { var ListCard = AddListCardAttachment(replyActivity, list, flighinput.JourneyDate.ToUniversalTime().Date); } else { replyActivity.Text = $"Flights are not available for selected date. Please check another date."; } }