本文整理汇总了C#中MongoRepository.Update方法的典型用法代码示例。如果您正苦于以下问题:C# MongoRepository.Update方法的具体用法?C# MongoRepository.Update怎么用?C# MongoRepository.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoRepository
的用法示例。
在下文中一共展示了MongoRepository.Update方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAndUpdateTest
public void AddAndUpdateTest()
{
IRepository<Customer> _customerRepo = new MongoRepository<Customer>();
IRepositoryManager<Customer> _customerMan = new MongoRepositoryManager<Customer>();
Assert.IsFalse(_customerMan.Exists);
var customer = new Customer();
customer.FirstName = "Bob";
customer.LastName = "Dillon";
customer.Phone = "0900999899";
customer.Email = "[email protected]";
customer.HomeAddress = new Address
{
Address1 = "North kingdom 15 west",
Address2 = "1 north way",
PostCode = "40990",
City = "George Town",
Country = "Alaska"
};
_customerRepo.Add(customer);
Assert.IsTrue(_customerMan.Exists);
Assert.IsNotNull(customer.Id);
// fetch it back
var alreadyAddedCustomer = _customerRepo.Where(c => c.FirstName == "Bob").Single();
Assert.IsNotNull(alreadyAddedCustomer);
Assert.AreEqual(customer.FirstName, alreadyAddedCustomer.FirstName);
Assert.AreEqual(customer.HomeAddress.Address1, alreadyAddedCustomer.HomeAddress.Address1);
alreadyAddedCustomer.Phone = "10110111";
alreadyAddedCustomer.Email = "[email protected]";
_customerRepo.Update(alreadyAddedCustomer);
// fetch by id now
var updatedCustomer = _customerRepo.GetById(customer.Id);
Assert.IsNotNull(updatedCustomer);
Assert.AreEqual(alreadyAddedCustomer.Phone, updatedCustomer.Phone);
Assert.AreEqual(alreadyAddedCustomer.Email, updatedCustomer.Email);
Assert.IsTrue(_customerRepo.Exists(c => c.HomeAddress.Country == "Alaska"));
}
示例2: BatchTest
public void BatchTest()
{
IRepository<Customer> _customerRepo = new MongoRepository<Customer>();
var custlist = new List<Customer>(new Customer[] {
new Customer() { FirstName = "Customer A" },
new Customer() { FirstName = "Client B" },
new Customer() { FirstName = "Customer C" },
new Customer() { FirstName = "Client D" },
new Customer() { FirstName = "Customer E" },
new Customer() { FirstName = "Client F" },
new Customer() { FirstName = "Customer G" },
});
//Insert batch
_customerRepo.Add(custlist);
var count = _customerRepo.Count();
Assert.AreEqual(7, count);
foreach (Customer c in custlist)
Assert.AreNotEqual(new string('0', 24), c.Id);
//Update batch
foreach (Customer c in custlist)
c.LastName = c.FirstName;
_customerRepo.Update(custlist);
foreach (Customer c in _customerRepo)
Assert.AreEqual(c.FirstName, c.LastName);
//Delete by criteria
_customerRepo.Delete(f => f.FirstName.StartsWith("Client"));
count = _customerRepo.Count();
Assert.AreEqual(4, count);
//Delete specific object
_customerRepo.Delete(custlist[0]);
//Test AsQueryable
var selectedcustomers = from cust in _customerRepo
where cust.LastName.EndsWith("C") || cust.LastName.EndsWith("G")
select cust;
Assert.AreEqual(2, selectedcustomers.ToList().Count);
count = _customerRepo.Count();
Assert.AreEqual(3, count);
//Drop entire repo
new MongoRepositoryManager<Customer>().Drop();
count = _customerRepo.Count();
Assert.AreEqual(0, count);
}
示例3: CollectionNamesTest
public void CollectionNamesTest()
{
var a = new MongoRepository<Animal>();
var am = new MongoRepositoryManager<Animal>();
var va = new Dog();
Assert.IsFalse(am.Exists);
a.Update(va);
Assert.IsTrue(am.Exists);
Assert.IsInstanceOfType(a.GetById(va.Id), typeof(Dog));
Assert.AreEqual(am.Name, "AnimalsTest");
Assert.AreEqual(a.CollectionName, "AnimalsTest");
var cl = new MongoRepository<CatLike>();
var clm = new MongoRepositoryManager<CatLike>();
var vcl = new Lion();
Assert.IsFalse(clm.Exists);
cl.Update(vcl);
Assert.IsTrue(clm.Exists);
Assert.IsInstanceOfType(cl.GetById(vcl.Id), typeof(Lion));
Assert.AreEqual(clm.Name, "Catlikes");
Assert.AreEqual(cl.CollectionName, "Catlikes");
var b = new MongoRepository<Bird>();
var bm = new MongoRepositoryManager<Bird>();
var vb = new Bird();
Assert.IsFalse(bm.Exists);
b.Update(vb);
Assert.IsTrue(bm.Exists);
Assert.IsInstanceOfType(b.GetById(vb.Id), typeof(Bird));
Assert.AreEqual(bm.Name, "Birds");
Assert.AreEqual(b.CollectionName, "Birds");
var l = new MongoRepository<Lion>();
var lm = new MongoRepositoryManager<Lion>();
var vl = new Lion();
//Assert.IsFalse(lm.Exists); //Should already exist (created by cl)
l.Update(vl);
Assert.IsTrue(lm.Exists);
Assert.IsInstanceOfType(l.GetById(vl.Id), typeof(Lion));
Assert.AreEqual(lm.Name, "Catlikes");
Assert.AreEqual(l.CollectionName, "Catlikes");
var d = new MongoRepository<Dog>();
var dm = new MongoRepositoryManager<Dog>();
var vd = new Dog();
//Assert.IsFalse(dm.Exists);
d.Update(vd);
Assert.IsTrue(dm.Exists);
Assert.IsInstanceOfType(d.GetById(vd.Id), typeof(Dog));
Assert.AreEqual(dm.Name, "AnimalsTest");
Assert.AreEqual(d.CollectionName, "AnimalsTest");
var m = new MongoRepository<Bird>();
var mm = new MongoRepositoryManager<Bird>();
var vm = new Macaw();
//Assert.IsFalse(mm.Exists);
m.Update(vm);
Assert.IsTrue(mm.Exists);
Assert.IsInstanceOfType(m.GetById(vm.Id), typeof(Macaw));
Assert.AreEqual(mm.Name, "Birds");
Assert.AreEqual(m.CollectionName, "Birds");
var w = new MongoRepository<Whale>();
var wm = new MongoRepositoryManager<Whale>();
var vw = new Whale();
Assert.IsFalse(wm.Exists);
w.Update(vw);
Assert.IsTrue(wm.Exists);
Assert.IsInstanceOfType(w.GetById(vw.Id), typeof(Whale));
Assert.AreEqual(wm.Name, "Whale");
Assert.AreEqual(w.CollectionName, "Whale");
}
示例4: GetInstagramFeeds
//.........这里部分代码省略.........
objInstagramFeed.ImageUrl = userinf2.data[j].caption.from.profile_picture;
}
catch { }
try
{
objInstagramFeed.FromId = userinf2.data[j].caption.from.id;
}
catch { }
try
{
objInstagramFeed.FeedUrl = userinf2.data[j].link;
}
catch { }
//try
//{
// objInstagramFeed.UserId = objInsAccount.UserId.;
//}
//catch { }
var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
var task = Task.Run(async () =>
{
return await ret;
});
int count = task.Result.Count;
if (count < 1)
{
instagramFeedRepo.Add(objInstagramFeed);
}
else
{
FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl);
instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter);
}
//if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
//{
// objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
//}
List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>();
usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
{
try
{
Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment();
try
{
objInstagramComment.Comment = usercmts.data[cmt].text;
}
catch { }
try
{
objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
}
catch { }
try
{
objInstagramComment.CommentId = usercmts.data[cmt].id;
}
catch { }
//try
示例5: FacebookComposeMessageRss
public string FacebookComposeMessageRss(string message, string profileid, string title, string link, string rssFeedId)
{
string ret = "";
Domain.Socioboard.Domain.FacebookAccount objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(profileid);
FacebookClient fb = new FacebookClient();
MongoRepository rssfeedRepo = new MongoRepository("RssFeed");
try
{
fb.AccessToken = objFacebookAccount.AccessToken;
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
var args = new Dictionary<string, object>();
args["message"] = message;
//args["description"] = title;
args["link"] = link;
ret = fb.Post("v2.0/" + objFacebookAccount.FbUserId + "/feed", args).ToString();
//RssFeedsRepository objrssfeed = new RssFeedsRepository();
//objrssfeed.updateFeedStatus(Guid.Parse(userid), message);
var builders = Builders<BsonDocument>.Filter;
FilterDefinition<BsonDocument> filter = builders.Eq("strId", rssFeedId);
var update = Builders<BsonDocument>.Update.Set("Status", true);
rssfeedRepo.Update<Domain.Socioboard.MongoDomain.RssFeed>(update, filter);
return ret = "Messages Posted Successfully";
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return ret = "Message Could Not Posted";
}
}
示例6: InstagramLikeUnLike
public string InstagramLikeUnLike(string LikeCount, string IsLike, string FeedId, string InstagramId, string UserId)
{
MongoRepository instagramFeedRepo = new MongoRepository("InstagramFeed");
string str = string.Empty;
//GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"], ConfigurationManager.AppSettings["InstagramClientSec"], ConfigurationManager.AppSettings["RedirectUrl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
//oAuthInstagram _api = new oAuthInstagram();
//_api = oAuthInstagram.GetInstance(configi);
try
{
objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId);
LikesController objlikes = new LikesController();
int islike = Convert.ToInt32(IsLike);
int LikeCounts = Convert.ToInt32(LikeCount);
if (islike == 0)
{
islike = 1;
bool dd = objlikes.PostUserLike(FeedId, objInstagramAccount.AccessToken);
LikeCounts++;
//objInstagramFeedRepository.UpdateLikesOfProfile(FeedId, islike, LikeCounts);
str = "unlike";
}
else
{
islike = 0;
bool i = objlikes.DeleteLike(FeedId, objInstagramAccount.AccessToken);
LikeCounts = LikeCounts - 1;
//objInstagramFeedRepository.UpdateLikesOfProfile(FeedId, islike, LikeCounts);
str = "like";
}
FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", FeedId);
var update = Builders<BsonDocument>.Update.Set("IsLike", islike).Set("LikeCount", LikeCounts);
instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter);
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
return str;
}
示例7: GetInstagramSelfFeeds
//.........这里部分代码省略.........
{
objInstagramFeed.Feed = item["caption"]["text"].ToString();
}
catch { }
try
{
objInstagramFeed.ImageUrl = item["user"]["profile_picture"].ToString();
}
catch { }
try
{
objInstagramFeed.FromId = item["user"]["id"].ToString();
}
catch { }
try
{
objInstagramFeed.FeedUrl = item["link"].ToString();
}
catch { }
var ret = instagramFeedRepo.Find<Domain.Socioboard.MongoDomain.InstagramFeed>(t => t.FeedId.Equals(objInstagramFeed.FeedId) && t.InstagramId.Equals(objInstagramFeed.InstagramId));
var task = Task.Run(async () =>
{
return await ret;
});
int count = task.Result.Count;
if (count < 1)
{
instagramFeedRepo.Add(objInstagramFeed);
}
else
{
FilterDefinition<BsonDocument> filter = new BsonDocument("FeedId", objInstagramFeed.FeedId);
var update = Builders<BsonDocument>.Update.Set("IsLike", objInstagramFeed.IsLike).Set("CommentCount", objInstagramFeed.CommentCount).Set("LikeCount", objInstagramFeed.LikeCount).Set("Type", objInstagramFeed.Type).Set("VideoUrl", objInstagramFeed.VideoUrl);
instagramFeedRepo.Update<Domain.Socioboard.MongoDomain.InstagramFeed>(update, filter);
}
List<Domain.Socioboard.MongoDomain.InstagramComment> lstInstagramComment = new List<Domain.Socioboard.MongoDomain.InstagramComment>();
usercmts = objComment.GetComment(objInstagramFeed.FeedId, accessToken);
for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
{
try
{
Domain.Socioboard.MongoDomain.InstagramComment objInstagramComment = new Domain.Socioboard.MongoDomain.InstagramComment();
try
{
objInstagramComment.Comment = usercmts.data[cmt].text;
}
catch { }
try
{
objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
}
catch { }
try
{
objInstagramComment.CommentId = usercmts.data[cmt].id;
}
catch { }
try
{
objInstagramComment.FeedId = objInstagramFeed.FeedId;
}
catch { }
try
{
objInstagramComment.InstagramId = instagramId;
}
catch { }
try
{
objInstagramComment.FromName = usercmts.data[cmt].from.username;
}
catch { }
try
{
objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
}
catch { }
lstInstagramComment.Add(objInstagramComment);
}
catch (Exception ex)
{
}
}
instagarmCommentRepo.AddList(lstInstagramComment);
}
catch (Exception ex)
{
}
}
}
}
catch (Exception ex)
{
}
}
示例8: SaveToDatabase
public static void SaveToDatabase()
{
var psrepo = new MongoRepository<ProductionSystem>();
psrepo.Update(ProductionSystem);
}
示例9: RepositoryUpdateTest
public void RepositoryUpdateTest()
{
var target = new MongoContext();
var repository = new MongoRepository<Employee>(target);
var expected = "Albert2";
Employee employee = null;
Yekzen.QualityTools.UnitTest.ExceptionAssert.InconclusiveWhenThrows<UnreachableException>(() => { employee = InsertInternal(repository); });
employee.FirstName = expected;
repository.Update(p => p.Id == employee.Id,employee);
Yekzen.QualityTools.UnitTest.ExceptionAssert.InconclusiveWhenThrows<UnreachableException>(() => { employee = repository.Single(p => p.Id == employee.Id); });
var actual = employee.FirstName;
Assert.AreEqual(expected, actual);
}
示例10: TwitterComposeMessageRss
public string TwitterComposeMessageRss(string message, string profileid, string rssFeedId)
{
string ret = "";
Domain.Socioboard.Domain.TwitterAccount objTwitterAccount = objTwitterAccountRepository.getUserInformation(profileid);
oAuthTwitter OAuthTwt = new oAuthTwitter();
OAuthTwt.AccessToken = objTwitterAccount.OAuthToken;
OAuthTwt.AccessTokenSecret = objTwitterAccount.OAuthSecret;
OAuthTwt.TwitterScreenName = objTwitterAccount.TwitterScreenName;
OAuthTwt.TwitterUserId = objTwitterAccount.TwitterUserId;
this.SetCofigDetailsForTwitter(OAuthTwt);
Tweet twt = new Tweet();
MongoRepository rssfeedRepo = new MongoRepository("RssFeed");
try
{
JArray post = twt.Post_Statuses_Update(OAuthTwt, message);
//RssFeedsRepository objrssfeed = new RssFeedsRepository();
//objrssfeed.updateFeedStatus(Guid.Parse(userid), message);
var builders = Builders<BsonDocument>.Filter;
FilterDefinition<BsonDocument> filter = builders.Eq("strId", rssFeedId);
var update = Builders<BsonDocument>.Update.Set("Status", true);
rssfeedRepo.Update<Domain.Socioboard.MongoDomain.RssFeed>(update, filter);
return ret = "Messages Posted Successfully";
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return ret = "Message Could Not Posted";
}
}