Ejemplo n.º 1
0
        public async Task LeaveCareAsync(string careId, string userId, UserTakeInfo.Status status)
        {
            var user = await FindUserByIdAsync(userId);

            var takeInfo = user?.TakenCares.Find(info => info.Id == careId);

            if (takeInfo == null)
            {
                return;
            }

            takeInfo.TakeStatus     = status;
            takeInfo.CompletionTime = DateTime.Now;

            var userUpdater = Builders <User> .Update.Set(nameof(User.TakenCares), user.TakenCares);

            var searchFilter = Builders <User> .Filter.Eq("_id", new BsonObjectId(new ObjectId(userId)));

            await _usersCollection.UpdateOneAsync(searchFilter, userUpdater);
        }
Ejemplo n.º 2
0
        public async Task CloseCareAsync(string careId, UserTakeInfo.Status status)
        {
            var care = await FindCareByIdAsync(careId);

            if (care == null)
            {
                return;
            }

            var careUpdater = Builders <Care> .Update.Set(nameof(Care.Closed), true);

            if (status == UserTakeInfo.Status.ClosedByCreator)
            {
                careUpdater.Set(nameof(Care.TakenBy), "");
            }

            var searchFilter = Builders <Care> .Filter.Eq("_id", new BsonObjectId(new ObjectId(careId)));

            await _careCollection.UpdateOneAsync(searchFilter, careUpdater);

            await _usersContext.LeaveCareAsync(careId, care.TakenBy, status);
        }
Ejemplo n.º 3
0
        public async Task CloseDeliveryAsync(string deliveryId, UserTakeInfo.Status status)
        {
            var delivery = await FindDeliveryByIdAsync(deliveryId);

            if (delivery == null)
            {
                return;
            }

            var deliveryUpdater = Builders <Delivery> .Update.Set(nameof(Delivery.Closed), true);

            if (status == UserTakeInfo.Status.ClosedByCreator)
            {
                deliveryUpdater.Set(nameof(Delivery.TakenBy), "");
            }

            var searchFilter = Builders <Delivery> .Filter.Eq("_id", new BsonObjectId(new ObjectId(deliveryId)));

            await _deliveryCollection.UpdateOneAsync(searchFilter, deliveryUpdater);

            await _usersContext.LeaveDeliveryAsync(deliveryId, delivery.TakenBy, status);
        }