//Check file is already registered public bool FileIsAlreadyRegistered(string fileName) { var file = new FileModel { Id = ObjectId.GenerateNewId(), FileName = fileName }; var fileRepository = new FileRepository(); var files = fileRepository.GetFiles(); if (files.Cast <FileModel>().Any(f => f.FileName == fileName)) { return(true); } fileRepository.AddFileToDb(file); return(false); }