Ejemplo n.º 1
0
        /// <summary>
        /// Gets the user with ID <paramref name="userId" />.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <returns>
        /// A user with matching ID <paramref name="userId" />, otherwise <see langword="null" />
        /// </returns>
        protected override User DoGetUser(string userId)
        {
            MongoQueryBuilder queryBuilder = new MongoQueryBuilder();
            queryBuilder.AddIfNotNull(iApplyDb.UserAccess._ID, userId, uid => new BsonObjectId(new ObjectId(uid)));

            MongoCollection<BsonDocument> userCollection = this.database.GetCollection(iApplyDb.UserAccess._COLLECTION_NAME);
            BsonDocument document = userCollection.FindOne(queryBuilder.ToAndEqQuery());

            if (document == null)
            {
                return null;
            }

            return BsonConverter.ConvertToObjectViaJson<User>(document);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates an application with a new originator.
        /// </summary>
        /// <param name="applicationId">The application identifier.</param>
        /// <param name="originator">The originator.</param>
        /// <returns>
        /// The updated application.
        /// </returns>
        protected override iApply.DataContract.Application DoUpdateOriginator(string applicationId, AuthenticatedApplicationUser originator)
        {
            MongoQueryBuilder queryBuilder = new MongoQueryBuilder();
            queryBuilder.AddIfNotNull(iApplyDb.Application._ID, applicationId, a => new BsonObjectId(new ObjectId(a)));

            MongoCollection<BsonDocument> applicationCollection = this.database.GetCollection(iApplyDb.Application._COLLECTION_NAME);
            BsonDocument document = applicationCollection.FindOne(queryBuilder.ToAndEqQuery());

            if (document == null)
            {
                return null;
            }

            var application = BsonConverter.ConvertToObjectViaJson<iApply.DataContract.Application>(document);
            application.CreatedBy = originator;
            application.AssignedTo = originator.Id;
            application.AssignedToDisplayName = originator.DisplayName;
            application.ModifiedBy = originator.Id;

            BsonDocument applicationDocument = BsonConverter.ConvertToBsonViaJson(application);
            applicationCollection.Save(applicationDocument);

            return application;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves a file called <paramref name="filename" /> uploaded as part of application with
        /// ID <paramref name="applicationId" />.
        /// If more than one file with this name exists within the application, a file upload control
        /// name must be provided to resolve the conflict.
        /// </summary>
        /// <param name="applicationId">The ID of the application to get uploaded files from.</param>
        /// <param name="filename">The filename of the uploaded file.</param>
        /// <param name="controlName">Optional name of the file upload control, used to resolve filename conflicts.</param>
        /// <returns>
        /// A serialisable file with name <paramref name="filename" />.
        /// </returns>
        protected override FileSerializable DoGetUploadedFile(string applicationId, string filename, string controlName = null)
        {
            MongoQueryBuilder queryBuilder = new MongoQueryBuilder();
            queryBuilder.AddIfNotNull(iApplyDb.ApplicationAttachments.APPLICATION_ID, applicationId, aid => new BsonString(aid));
            queryBuilder.AddIfNotNull(iApplyDb.ApplicationAttachments.CONTROL_NAME, controlName, cn => new BsonString(cn));
            queryBuilder.AddIfNotNull(iApplyDb.ApplicationAttachments.Files.FILE_IDENTIFIER_ABSOLUTE_PATH, filename, fn => new BsonString(fn));

            MongoCollection<BsonDocument> fileCollection = this.database.GetCollection(iApplyDb.ApplicationAttachments._COLLECTION_NAME);
            MongoCursor<BsonDocument> documents = fileCollection.Find(queryBuilder.ToAndEqQuery());

            if (!documents.Any())
            {
                throw new FileNotFoundException(string.Format(ExceptionMessages.NoFileFound, filename) + (controlName == null ? string.Empty : string.Format(ExceptionMessages.WithinControl, controlName)));
            }

            if (documents.Count() > 1)
            {
                throw new Exception(string.Format(ExceptionMessages.MultipleFilesFound, filename));
            }

            BsonDocument fileDoc = documents.First();
            BsonArray files = fileDoc[iApplyDb.ApplicationAttachments.FILES].AsBsonArray;

            BsonValue file = files.First(f => f[iApplyDb.ApplicationAttachments.Files.FILE_IDENTIFIER] == filename);
            return new FileSerializable(file[iApplyDb.ApplicationAttachments.Files.FILE_IDENTIFIER].AsString, file[iApplyDb.ApplicationAttachments.Files.FILE].AsByteArray);
        }