コード例 #1
0
        //Update team into Inmemory Db and return teams
        public async Task <Teams> TeamUpdateAsync(Teams teams)
        {
            ReplaceOneResult updateResult = await _context.teams.ReplaceOneAsync(filter : g => g.TeamName == teams.TeamName, replacement : teams);

            return(teams);
        }
コード例 #2
0
 /// <summary>
 /// Update a page version
 /// </summary>
 /// <param name="pageVersion">Page version to update</param>
 /// <returns>Task</returns>
 public async Task UpdatePageVersion(KirjaPageVersion pageVersion)
 {
     ReplaceOneResult result = await _PageVersionCollection.ReplaceOneAsync(p => p.Id == pageVersion.Id, pageVersion);
 }
コード例 #3
0
 /// <summary>
 /// Updates a task board
 /// </summary>
 /// <param name="board">Task Board</param>
 /// <returns>Task</returns>
 public async Task UpdateTaskBoard(TaskBoard board)
 {
     ReplaceOneResult result = await _TaskBoardCollection.ReplaceOneAsync(b => b.Id == board.Id, board);
 }
コード例 #4
0
        public IActionResult PutPerson(string id, [FromBody] Person value)
        {
            ReplaceOneResult result = MongoCollectionPerson.ReplaceOne(x => x.Id == id, value);

            return(Ok(result));
        }
コード例 #5
0
 /// <summary>
 /// Updates a quest
 /// </summary>
 /// <param name="quest">Quest to update</param>
 /// <returns>Task</returns>
 public async Task UpdateQuest(AikaQuest quest)
 {
     ReplaceOneResult result = await _QuestCollection.ReplaceOneAsync(q => q.Id == quest.Id, quest);
 }
コード例 #6
0
        public async Task <T> Update(T model)
        {
            ReplaceOneResult updateResult = await Collection.ReplaceOneAsync(filter : g => g.Id == model.Id, replacement : model);

            return(model);
        }
コード例 #7
0
 public static bool Success(this ReplaceOneResult result)
 {
     return(result.IsAcknowledged && result.IsModifiedCountAvailable && result.ModifiedCount == 1);
 }
コード例 #8
0
        public static bool StartUpdateASXListedCompaniesBatch(StocksDB stocksDB, out ASXListedCompanyBatch batch)
        {
            batch = null;
            string collectionName = "ASXListedCompanies";

            if (stocksDB is null)
            {
                stocksDB = new StocksDB();
            }
            batch = GetASXListedCompaniesBatchRecord(stocksDB);
            var collection = stocksDB.GetCollection <ASXListedCompanyBatch>(collectionName);

            if (batch == null)
            {
                batch                         = new ASXListedCompanyBatch();
                batch.BatchName               = ASXListedCompanyBatch.cBatchName;
                batch.Dates                   = new Dates();
                batch.Dates.CreatedDate       = DateTime.Now;
                batch.Dates.UpdateStartedDate = batch.Dates.CreatedDate;
                var filter = Builders <ASXListedCompanyBatch> .Filter.Eq("BatchName", ASXListedCompanyBatch.cBatchName);

                try
                {
                    collection.InsertOne(batch);
                }
                catch (Exception e)
                {
                    Console.Write(e);
                    return(false);
                }
            }
            else
            {
                DateTime updateStartedDate = DateTime.Now;

                //Check for in progress or run away updates
                if (!batch.Dates.LastUpdatedDate.HasValue ||
                    (batch.Dates.UpdateStartedDate > batch.Dates.LastUpdatedDate &&
                     batch.Dates.UpdateStartedDate.Value.AddHours(1) > updateStartedDate)
                    )
                {
                    return(false);
                }

                var filter = Builders <ASXListedCompanyBatch> .Filter.And(
                    Builders <ASXListedCompanyBatch> .Filter.Eq("BatchName", ASXListedCompanyBatch.cBatchName),
                    Builders <ASXListedCompanyBatch> .Filter.Eq("Dates.LastUpdatedDate", batch.Dates.LastUpdatedDate),
                    Builders <ASXListedCompanyBatch> .Filter.Eq("Dates.UpdateStartedDate", batch.Dates.UpdateStartedDate));

                try
                {
                    batch.Dates.UpdateStartedDate = updateStartedDate;
                    ReplaceOneResult replaceResult = collection.ReplaceOne(filter, batch);
                    return(replaceResult.ModifiedCount == 1);
                }
                catch (Exception e)
                {
                    Console.Write(e);
                    return(false);
                }
            }

            return(true);
        }
コード例 #9
0
        public static bool SaveWatchlist(StocksDB stocksDB, string login, Watchlist watchlist)
        {
            User   user           = null;
            string collectionName = "watchlists";

            if (stocksDB is null)
            {
                stocksDB = new StocksDB();
            }
            user = GetOrCreateUser(stocksDB, login);
            if (user == null)
            {
                throw new UserException("Unable to access user:"******"Id", watchlist.Id);

            try
            {
                user.LastAccessDate = lastAccessDate;
                ReplaceOneResult replaceResult = collection.ReplaceOne(filter, watchlist, new UpdateOptions {
                    IsUpsert = true
                });
                if (replaceResult.ModifiedCount != 1 && !(replaceResult.IsAcknowledged && replaceResult.UpsertedId != null))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                throw new WatchlistException("Failed to save watchlist:" + watchlist.Name + ":" + e.Message);
            }

            return(true);
        }
コード例 #10
0
        public async Task <bool> UpdateNote(ulong UserId, Note Note)
        {
            ReplaceOneResult Result = await Collection.ReplaceOneAsync((filter) => filter.UserId == UserId, Note);

            return(Result.IsAcknowledged);
        }
コード例 #11
0
        public async Task <bool> Update(User user)
        {
            ReplaceOneResult updateResult = await _context.Users.ReplaceOneAsync(filter : b => b.Id == user.Id, replacement : user);

            return(updateResult.IsAcknowledged && updateResult.ModifiedCount > 0);
        }
コード例 #12
0
 /// <summary>
 /// Updates an Flex Field Object
 /// </summary>
 /// <param name="flexFieldObject">Flex Field Object to update</param>
 /// <returns>Task</returns>
 public async Task UpdateFlexFieldObject(T flexFieldObject)
 {
     ReplaceOneResult result = await _ObjectCollection.ReplaceOneAsync(n => n.Id == flexFieldObject.Id, flexFieldObject);
 }
コード例 #13
0
        public bool UpdatePayment(Payment payment)
        {
            ReplaceOneResult res = _payments.ReplaceOne(p => p.Id == payment.Id, payment);

            return(res.MatchedCount > 0);
        }
コード例 #14
0
        public async Task <bool> UpdateMemberAsync(Member member)
        {
            ReplaceOneResult updateResult = await _context.Members.ReplaceOneAsync(filter : m => m.Id == member.Id, replacement : member);

            return(updateResult.IsAcknowledged && updateResult.ModifiedCount > 0);
        }
コード例 #15
0
        public bool UpdateGame(Game game)
        {
            ReplaceOneResult result = _games.ReplaceOne(g => g.Id == game.Id, game);

            return(result.MatchedCount > 0);
        }
コード例 #16
0
        public async Task <ItinerarySetRes> SetItinerary(ItinerarySetReq request)
        {
            ItinerarySetRes response = new ItinerarySetRes();

            try
            {
                mItinerary itinerary;

                //To enter new itinerary element in existing itinerary days
                if (request.IsExtraItineraryElement == false)
                {
                    if (request.IsNewVersion)
                    {
                        //Add
                        itinerary = _MongoContext.mItinerary.AsQueryable().Where(x => x.ItineraryID == request.itinerary.ItineraryID).FirstOrDefault();

                        itinerary._Id         = ObjectId.Empty;
                        itinerary.ItineraryID = Guid.NewGuid().ToString();
                        itinerary.Version     = itinerary.Version + 1;
                        itinerary.CreateUser  = itinerary.CreateUser;
                        itinerary.CreateDate  = DateTime.Now;

                        await _MongoContext.mItinerary.InsertOneAsync(itinerary);

                        response.ResponseStatus.Status       = "Success";
                        response.ResponseStatus.ErrorMessage = "Saved Successfully.";
                    }
                    else
                    {
                        //Update
                        itinerary = _MongoContext.mItinerary.AsQueryable().Where(x => x.ItineraryID == request.itinerary.ItineraryID).FirstOrDefault();

                        foreach (var days in itinerary.ItineraryDays)
                        {
                            foreach (var daysReq in request.itinerary.ItineraryDays)
                            {
                                if (days.ItineraryDaysId == daysReq.ItineraryDaysId)
                                {
                                    foreach (var desc in days.ItineraryDescription)
                                    {
                                        foreach (var descReq in daysReq.ItineraryDescription)
                                        {
                                            if (desc.PositionId == descReq.PositionId)
                                            {
                                                desc.IsDeleted   = descReq.IsDeleted;
                                                desc.ProductName = string.IsNullOrEmpty(descReq.ProductName) ? desc.ProductName : descReq.ProductName;
                                                desc.StartTime   = string.IsNullOrEmpty(descReq.StartTime) ? desc.StartTime : descReq.StartTime;
                                                desc.EndTime     = string.IsNullOrEmpty(descReq.EndTime) ? desc.EndTime : descReq.EndTime;
                                                desc.City        = string.IsNullOrEmpty(descReq.City) ? desc.City : descReq.City;
                                                desc.TLRemarks   = descReq.TLRemarks;
                                                desc.OPSRemarks  = descReq.OPSRemarks;
                                                desc.EditDate    = DateTime.Now;
                                                desc.EditUser    = !string.IsNullOrWhiteSpace(descReq.EditUser) ? descReq.EditUser : request.itinerary.EditUser;
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }

                        ReplaceOneResult replaceResult = await _MongoContext.mItinerary.ReplaceOneAsync(Builders <mItinerary> .Filter.Eq("ItineraryID", itinerary.ItineraryID), itinerary);

                        response.ResponseStatus.Status       = replaceResult.MatchedCount > 0 ? "Success" : "Failure";
                        response.ResponseStatus.ErrorMessage = replaceResult.MatchedCount > 0 ? "Saved Successfully." : "Details not updated.";
                    }
                }
                else
                {
                    //IsExtraItineraryElement is true

                    itinerary = _MongoContext.mItinerary.AsQueryable().Where(x => x.QRFID == request.itinerary.QRFID && x.ItineraryID == request.itinerary.ItineraryID).FirstOrDefault();

                    if (itinerary != null)
                    {
                        foreach (var day in itinerary.ItineraryDays)
                        {
                            foreach (var reqDay in request.itinerary.ItineraryDays)
                            {
                                if (reqDay.ItineraryDaysId == day.ItineraryDaysId)
                                {
                                    day.ItineraryDescription.Add(new ItineraryDescriptionInfo
                                    {
                                        PositionId  = Guid.NewGuid().ToString(),
                                        City        = reqDay.ItineraryDescription[0].City,
                                        ProductType = reqDay.ItineraryDescription[0].ProductType == null ? "" : reqDay.ItineraryDescription[0].ProductType,
                                        StartTime   = reqDay.ItineraryDescription[0].StartTime,
                                        EndTime     = reqDay.ItineraryDescription[0].EndTime,
                                        Type        = reqDay.ItineraryDescription[0].Type == null ? "" : reqDay.ItineraryDescription[0].Type,
                                        ProductName = reqDay.ItineraryDescription[0].ProductName == null ? "" : reqDay.ItineraryDescription[0].ProductName,
                                        NumberOfPax = reqDay.ItineraryDescription[0].NumberOfPax,
                                        KeepAs      = reqDay.ItineraryDescription[0].KeepAs == null ? "" : reqDay.ItineraryDescription[0].KeepAs,
                                        IsDeleted   = reqDay.ItineraryDescription[0].IsDeleted,
                                        CreateDate  = DateTime.Now,
                                        CreateUser  = !string.IsNullOrWhiteSpace(request.itinerary.CreateUser) ? request.itinerary.CreateUser : itinerary.CreateUser
                                    });
                                }
                            }
                        }
                        var resultFlag = await _MongoContext.mItinerary.UpdateOneAsync(Builders <mItinerary> .Filter.Eq("ItineraryID", itinerary.ItineraryID),
                                                                                       Builders <mItinerary> .Update.Set("ItineraryDays", itinerary.ItineraryDays));

                        response.ResponseStatus.Status       = "Success";
                        response.ResponseStatus.ErrorMessage = "Saved Successfully.";
                    }
                    else
                    {
                        response.ResponseStatus.Status       = "Error";
                        response.ResponseStatus.ErrorMessage = "No records to insert.";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = ex.Message;
            }
            return(response);
        }
コード例 #17
0
 /// <summary>
 /// Updates a chapter detail
 /// </summary>
 /// <param name="chapterDetail">Chapter detail to update</param>
 /// <returns>Task</returns>
 public async Task UpdateChapterDetail(AikaChapterDetail chapterDetail)
 {
     ReplaceOneResult result = await _ChapterDetailCollection.ReplaceOneAsync(c => c.Id == chapterDetail.Id, chapterDetail);
 }
コード例 #18
0
        public async Task <bool> UpdateRoom(ChatRoom room)
        {
            ReplaceOneResult updateResult = await _mongoDbContext.Rooms.ReplaceOneAsync(filter : r => r.ID == room.ID, replacement : room);

            return(updateResult.IsAcknowledged && updateResult.ModifiedCount > 0);
        }
コード例 #19
0
 public async Task UpdateAsync(T entity, CancellationToken token = default(CancellationToken))
 {
     ReplaceOneResult actionResult = await Entities
                                     .ReplaceOneAsync(n => n.Id.Equals(entity.Id), entity, new UpdateOptions { IsUpsert = true });
 }
コード例 #20
0
        public async Task <bool> Update(Product product)
        {
            ReplaceOneResult updateResult = await _context.Products.ReplaceOneAsync(filter : x => x.Id == product.Id, replacement : product);

            return(updateResult.ModifiedCount > 0 && updateResult.IsAcknowledged);
        }
コード例 #21
0
        static void Main(string[] args)
        {
            string                   connectionString = "mongodb+srv://<login>:<password>@<cluster>.mongodb.net/<database>?retryWrites=true&w=majority";
            IMongoClient             client           = new MongoClient(connectionString);
            IMongoDatabase           database         = client.GetDatabase("application");
            IMongoCollection <Infos> colInfos         = database.GetCollection <Infos>("infos");

            Console.WriteLine("Insert? (i)");

            string insert = Console.ReadLine();

            if (insert == "i")
            {
                Infos doc = new Infos();
                doc.Name    = "Lucas";
                doc.Surname = "Queiroz";
                doc.Date    = DateTime.Now;
                doc.Age     = 24;
                doc.Height  = 1.85;
                Console.WriteLine(colInfos.Database.DatabaseNamespace);
                colInfos.InsertOne(doc);
            }

            Console.WriteLine("Filter? (f)");

            string filter = Console.ReadLine();

            if (filter == "f")
            {
                Console.WriteLine("ID:");

                string id = Console.ReadLine();

                if (id.Trim() != null)
                {
                    Expression <Func <Infos, bool> > filterResponse = x => x.Id.Equals(ObjectId.Parse(id));

                    Infos news = colInfos.Find(filterResponse).FirstOrDefault();

                    Console.WriteLine(news.ToJson());
                }
            }

            Console.WriteLine("Update? (u)");

            string update = Console.ReadLine();

            if (update == "u")
            {
                Console.WriteLine("Name to update:");

                string name = Console.ReadLine();

                Expression <Func <Infos, bool> > filterResponse = x => x.Name.Equals(name);
                Infos info = colInfos.Find(filterResponse).FirstOrDefault();

                info.Name    = "John";
                info.Surname = "Due";
                info.Date    = DateTime.Now;
                info.Age     = 40;
                info.Height  = 1.95;

                ReplaceOneResult result = colInfos.ReplaceOne(filterResponse, info);
            }

            Console.WriteLine("Get all? (g)");

            string getAll = Console.ReadLine();

            if (getAll == "g")
            {
                IMongoQueryable <Infos> info = colInfos.AsQueryable().OrderBy(x => x.Name);
                info.ForEachAsync(x => Console.WriteLine(x.ToJson()));
            }

            Console.WriteLine("Delete? (d)");

            string delete = Console.ReadLine();

            if (delete == "d")
            {
                Console.WriteLine("ID:");

                string id = Console.ReadLine();


                if (id != null)
                {
                    Expression <Func <Infos, bool> > filterDelete = x => x.Id.Equals(ObjectId.Parse(id));
                    DeleteResult delresult = colInfos.DeleteOne(filterDelete);
                }
            }

            //https://medium.com/@fulviocanducci/mongodb-opera%C3%A7%C3%B5es-crud-com-c-2af4e77c046
        }
コード例 #22
0
        public async Task <ReplaceOneResult> EditAsync(Expression <Func <T, bool> > where, T model, UpdateOptions options, CancellationToken cancellationToken)
        {
            ReplaceOneResult replaceOneResult = await this.Collection.ReplaceOneAsync(where, model, options, cancellationToken);

            return(replaceOneResult);
        }
コード例 #23
0
 /// <summary>
 /// Updates a page
 /// </summary>
 /// <param name="page">Page to update</param>
 /// <returns>Task</returns>
 public async Task UpdatePage(KirjaPage page)
 {
     ReplaceOneResult result = await _PageCollection.ReplaceOneAsync(p => p.Id == page.Id, page);
 }
コード例 #24
0
        public async Task <ReplaceOneResult> EditAsync(FilterDefinition <T> query, T model, UpdateOptions options, CancellationToken cancellationToken)
        {
            ReplaceOneResult replaceOneResult = await this.Collection.ReplaceOneAsync(query, model, options, cancellationToken);

            return(replaceOneResult);
        }
コード例 #25
0
 /// <summary>
 /// Update a Kirja page review
 /// </summary>
 /// <param name="pageReview">Page review to update</param>
 /// <returns>Task</returns>
 public async Task UpdatePageReview(KirjaPageReview pageReview)
 {
     ReplaceOneResult result = await _PageReviewCollection.ReplaceOneAsync(p => p.Id == pageReview.Id, pageReview);
 }
コード例 #26
0
 public static bool IsSuccess(this ReplaceOneResult result)
 => result.IsAcknowledged && result.ModifiedCount > 0;
コード例 #27
0
 /// <summary>
 /// Updates a dialog
 /// </summary>
 /// <param name="dialog">Dialog</param>
 /// <returns>Task</returns>
 public async Task UpdateDialog(TaleDialog dialog)
 {
     ReplaceOneResult result = await _DialogCollection.ReplaceOneAsync(p => p.Id == dialog.Id, dialog);
 }
コード例 #28
0
 /// <summary>
 /// Updates a chapter overview
 /// </summary>
 /// <param name="chapterOverview">Chapter overview to update</param>
 /// <returns>Task</returns>
 public async Task UpdateChapterOverview(AikaChapterOverview chapterOverview)
 {
     ReplaceOneResult result = await _ChapterOverviewCollection.ReplaceOneAsync(c => c.Id == chapterOverview.Id, chapterOverview);
 }
コード例 #29
0
 /// <summary>
 /// Updates a task board category
 /// </summary>
 /// <param name="category">Task Board category</param>
 /// <returns>Task</returns>
 public async Task UpdateTaskBoardCategory(TaskBoardCategory category)
 {
     ReplaceOneResult result = await _TaskBoardCategoryCollection.ReplaceOneAsync(c => c.Id == category.Id, category);
 }
コード例 #30
0
        public async Task <bool> Update(Game game)
        {
            ReplaceOneResult updateResult = await _context.Games.ReplaceOneAsync(filter : g => g.Id == game.Id, replacement : game);

            return(updateResult.IsAcknowledged && updateResult.ModifiedCount > 0);
        }