예제 #1
0
        //
        // GET: /Dialog/

        public ActionResult AddDialog(string username, string advertid)
        {
            
            var user = MongoDbContext.db.GetCollection<UserContext>("UserContext").Find(c => c.Login == username).FirstAsync().GetAwaiter().GetResult();
            var dialog = MongoDbContext.db.GetCollection<Dialog>("Dialog").Find(c => c.AdvertId == advertid && c.userId == user.Id).FirstOrDefaultAsync().GetAwaiter().GetResult();
            if(dialog == null)
            {
                var advert = MongoDbContext.db.GetCollection<Advert>("Advert").Find(c => c.Id == advertid).FirstAsync().GetAwaiter().GetResult();
                dialog = new Dialog()
                {
                    Id = ObjectId.GenerateNewId().ToString(),
                    CreationDate = DateTime.Now,
                    UpdateDate = DateTime.Now,
                    AdvertId = advertid,
                    Messages = new List<Message>(),
                    userId = user.Id,
                    ownerId = advert.User.Id
                };
                MongoDbContext.db.GetCollection<Dialog>("Dialog").InsertOneAsync(dialog).Wait();
            }


            return RedirectToAction("Display", new { Id = dialog.Id });
        }
예제 #2
0
 public void AddDialog(Dialog dialog)
 {
     db.GetCollection<Dialog>("Dialog").InsertOneAsync(dialog).Wait();
 }